// // MPMutableExpressionTests.m // MathPad // // Created by Kim Wittenburg on 19.04.14. // Copyright (c) 2014 Kim Wittenburg. All rights reserved. // #import #import "MPExpression.h" #import "MPFunction.h" @interface MPMutableExpressionTests : XCTestCase @end @implementation MPMutableExpressionTests - (void)testMutating { MPMutableExpression *testExpression = [[MPMutableExpression alloc] initWithSymbols:@[@"1234", [[MPFunction alloc] init], @"5678", [[MPFunction alloc] init]]]; [testExpression appendString:@"90"]; XCTAssertEqual([testExpression numberOfSymbols], 5); // 1234 [] 5678 [] 90 [testExpression deleteSymbolsInRange:NSMakeRange(2, 4)]; XCTAssertEqual([testExpression numberOfSymbols], 3); // 12678 [] 90 [testExpression insertFunction:[[MPFunction alloc] init] atIndex:2]; XCTAssertEqual([testExpression numberOfSymbols], 5); // 12 [] 678 [] 90 [testExpression replaceSymbolsInRange:NSMakeRange(2, 5) withSymbols:@[[[MPFunction alloc] init]]]; XCTAssertEqual([testExpression numberOfSymbols], 3); // 12 [] 90 [testExpression setString:@"abc"]; XCTAssertEqual([testExpression numberOfSymbols], 1); // abc } - (void)testInvalidMutatingRange { @try { MPMutableExpression *testExpression = [[MPMutableExpression alloc] initWithSymbols:@[@"1234", [[MPFunction alloc] init], @"5678", [[MPFunction alloc] init]]]; [testExpression deleteSymbolsInRange:NSMakeRange(5, 17)]; XCTFail(@"Should have raised an exception"); } @catch (NSException *exception) {} } @end