Archived
1
This repository has been archived on 2022-08-08. You can view files and clone it. You cannot open issues or pull requests or push a commit.
Files
mathpad/MathPadTests/MPMutableExpressionTests.m

53 lines
1.6 KiB
Objective-C

//
// MPMutableExpressionTests.m
// MathPad
//
// Created by Kim Wittenburg on 19.04.14.
// Copyright (c) 2014 Kim Wittenburg. All rights reserved.
//
#import <XCTest/XCTest.h>
#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