#import <XCTest/XCTest.h>
#import "ViewController0.h"
#import "AppDelegate.h"
@interface PITaxTests : XCTestCase
@property (nonatomic,strong) ViewController0 *vc;
@end
@implementation PITaxTests
/*
XCTAssertEqualObjects 当两个对象不相等或者是其中一个对象为nil时,断言失败
XCTAssertEqual 当参数1不等于参数2时断言失败,用于C中的基本数据测试
XCTAssertNil 当参数不是nil时,断言失败
XCTAssertNotNil 当参数是nil时,断言失败
XCTAssertTrue 当表达式为false时,断言失败
XCTAssertFalse 当表达式为true时,断言失败
XCTAssertThrows 如果表达式没有抛出异常,则断言失败
XCTAssertNoThrow 如果表达式抛出异常,则断言失败
*/
- (void)setUp {
[supersetUp];
// Put setup code here. This method is called before the invocation of each test method in the class.
self.vc = [[ViewController0alloc] init];
}
- (void)tearDown {
// Put teardown code here. This method is called after the invocation of each test method in the class.
self.vc =nil;
[supertearDown];
}
- (void)testExample {
// This is an example of a functional test case.
// Use XCTAssert and related functions to verify your tests produce the correct results.
}
- (void)testPerformanceExample {
// This is an example of a performance test case.
[selfmeasureBlock:^{
// Put the code you want to measure the time of here.
}];
}
// 测试不输入直接点击“计算”按钮的情况
- (void)testButtonClickInputBlank
{
// 设定输入值
self.vc.textField.text = @"";
// 调用ButtonClick
[self.vcbuttonClick:nil];
// 取得输出结果
XCTAssertEqual(self.vc.myTax,0.00,@"期望值是:0.00实际值是:%f",self.vc.myTax);
}
// 测试整数
- (void)testButtonClickInputIntegerNumber
{
XCTAssertNotNil(self.vc,@"ViewController没有赋值");
// 设定输入值
self.vc.textField.text = @"8000";
// 调用ButtonClick
[self.vcbuttonClick:nil];
// 取得输出结果
XCTAssertEqual(self.vc.myTax,345.00,@"期望值是:345.00实际值是:%f",self.vc.myTax);
}
// 测试小数
- (void)testButtonClickInputOneDot
{
XCTAssertNotNil(self.vc,@"ViewController没有赋值");
// 设定输入值
self.vc.textField.text = @"8000.59";
// 调用ButtonClick
[self.vcbuttonClick:nil];
// 取得输出结果
XCTAssertEqual(self.vc.myTax,345.12,@"期望值是:345.12实际值是:%f",self.vc.myTax);
}
// 测试输入两个小数点的情况
- (void)testButtonClickInputTwoDot
{
XCTAssertNotNil(self.vc,@"ViewController没有赋值");
// 设定输入值
self.vc.textField.text = @"40000.50.56";
// 调用ButtonClick
[self.vcbuttonClick:nil];
// 取得输出结果
XCTAssertEqual(self.vc.myTax,8195.15,@"期望值是:8195.15实际值是:%f",self.vc.myTax);
}
// 测试有前导0的数据
- (void)testButtonClickInputfixZero
{
XCTAssertNotNil(self.vc,@"ViewController没有赋值");
// 设定输入值
self.vc.textField.text = @"08000.59";
// 调用ButtonClick
[self.vcbuttonClick:nil];
// 取得输出结果
XCTAssertEqual(self.vc.myTax,345.12,@"期望值是:345.12实际值是:%f",self.vc.myTax);
}
// 测试连在一起的两个小数点的情况
- (void)testButtonClickInputLinkDot
{
XCTAssertNotNil(self.vc,@"ViewController没有赋值");
// 设定输入值
self.vc.textField.text = @"40000.50..56";
// 调用ButtonClick
[self.vcbuttonClick:nil];
// 取得输出结果
XCTAssertEqual(self.vc.myTax,8195.15,@"期望值是:8195.15实际值是:%f",self.vc.myTax);
}
@end