Cog/SecondsFormatterTests/SecondsFormatterTests.m
Jan c5ac86725d
Two gigaseconds (#147)
* Fix look of position time field to match the rest of the UI.

* Fix typo.

* Improve position time display.

* Add days, hours support to position time display.

* Fix "Current Time" toolbar item geometry/layout.

* Don’t enforce leading double-digits in position time display.

* MainMenu.xib touched by Xcode.

* Implement and use MonospacedDigitTextFieldCell.
This way the digits of numbers in playlist columns consisting of mostly digits will be aligned vertically.

* Disable font scaling code without effect.

* Set "Current Time" toolbar item to use MonospacedDigitTextFieldCell.

* Improve SecondsFormatter.

* Merge in SecondsFormatter improvements from Play.

* Move formatter setup into XIB.

* Add CogTests.
These can later be used for integration tests.

* Add SecondsFormatterTests.
Tests are stubbed out.

* Pouring foundation for SecondsFormatterTests.

* Implement -testPositive.

* Replace unsigned with int in SecondsFormatter.

* Implement negative support, tests.

* Rewrite SecondsFormatter in preparation for better readability..

* Rewrite SecondsFormatter for better readability.

* Add negative zero support.

* Improve SecondsFormatter readability.

* Refactor into -stringForTimeInterval: in SecondsFormatter.

* Cleanup.

* Mark TimeField as space-indented.

* Replace custom time formatting code in TimeField with SecondsFormatter.

* Cleanup.

* Improve SecondsFormatter format strings.

* Add internal type for time calculations.

Co-authored-by: Jan Weiß <jan@geheimwerk.de>
2021-05-06 19:50:26 -07:00

131 lines
3.1 KiB
Objective-C

//
// SecondsFormatterTests.m
// SecondsFormatterTests
//
// Created by Jan on 05.05.21.
//
#import <XCTest/XCTest.h>
#import "SecondsFormatter.h"
@interface SecondsFormatterTests : XCTestCase
@end
@implementation SecondsFormatterTests
- (void)setUp
{
[super setUp];
// Put setup code here. This method is called before the invocation of each test method in the class.
}
- (void)tearDown
{
// Put teardown code here. This method is called after the invocation of each test method in the class.
[super tearDown];
}
- (void)testPositive
{
NSDictionary *testsDict =
@{
// key: test name, value: test string
@"Zero": @"0:00",
@"One Second": @"0:01",
@"One Minute": @"1:00",
@"One Hour": @"1:00:00",
@"One Day": @"1:00:00:00",
@"One of Each": @"1:01:01:01",
};
#define TEST_INFO @"Test name: %@, Source string: %@", testName, string
NSFormatter *secondsFormatter = [[SecondsFormatter alloc] init];
[testsDict enumerateKeysAndObjectsUsingBlock:
^(NSString *testName, NSString *string, BOOL * _Nonnull stop) {
NSNumber *value;
BOOL result =
[secondsFormatter getObjectValue:&value
forString:string
errorDescription:NULL];
XCTAssertTrue(result, TEST_INFO);
NSString *timeString = [secondsFormatter stringForObjectValue:value];
XCTAssertEqualObjects(string, timeString, TEST_INFO);
}];
}
- (void)testNegative
{
NSDictionary *testsDict =
@{
// key: test name, value: test string
@"Negative Zero": @"-0:00",
@"Negative One Second": @"-0:01",
@"Negative One Minute": @"-1:00",
@"Negative One Hour": @"-1:00:00",
@"Negative One Day": @"-1:00:00:00",
@"Negative One of Each": @"-1:01:01:01",
};
#define TEST_INFO @"Test name: %@, Source string: %@", testName, string
NSFormatter *secondsFormatter = [[SecondsFormatter alloc] init];
[testsDict enumerateKeysAndObjectsUsingBlock:
^(NSString *testName, NSString *string, BOOL * _Nonnull stop) {
NSNumber *value;
BOOL result =
[secondsFormatter getObjectValue:&value
forString:string
errorDescription:NULL];
XCTAssertTrue(result, TEST_INFO);
NSString *timeString = [secondsFormatter stringForObjectValue:value];
XCTAssertEqualObjects(string, timeString, TEST_INFO);
}];
}
- (void)testMalformed
{
NSDictionary *testsDict =
@{
// key: test name, value: test string
@"Empty String": @"",
@"Random String": @"abc",
@"Solitary Minus": @"-",
@"Malformed Seconds": @"0:60",
@"Malformed Minutes": @"60:00",
@"Malformed Hours": @"24:00:00",
@"Illegal #1": @":00",
@"Illegal #2": @"-:00",
};
#define TEST_INFO @"Test name: %@, Source string: %@", testName, string
NSFormatter *secondsFormatter = [[SecondsFormatter alloc] init];
[testsDict enumerateKeysAndObjectsUsingBlock:
^(NSString *testName, NSString *string, BOOL * _Nonnull stop) {
NSNumber *value;
BOOL result =
[secondsFormatter getObjectValue:&value
forString:string
errorDescription:NULL];
XCTAssertFalse(result, TEST_INFO);
}];
}
#if 0
- (void)testPerformanceExample
{
// This is an example of a performance test case.
[self measureBlock:^{
// Put the code you want to measure the time of here.
}];
}
#endif
@end