#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