Browse Source

Tests..

pull/113/head
Abhishek Banthia 3 years ago
parent
commit
431415f8bb
  1. 17
      Clocker/ClockerUnitTests/ClockerUnitTests.swift
  2. 2
      Clocker/CoreModelKit/Sources/CoreModelKit/TimezoneData.swift
  3. 6
      Clocker/CoreModelKit/Tests/CoreModelKitTests/TimezoneDataEqualityTests.swift

17
Clocker/ClockerUnitTests/ClockerUnitTests.swift

@ -109,8 +109,12 @@ class ClockerUnitTests: XCTestCase {
} }
func testDecoding() { func testDecoding() {
let timezone = TimezoneData.customObject(from: nil) let timezone1 = TimezoneData.customObject(from: nil)
XCTAssertNotNil(timezone) XCTAssertNotNil(timezone1)
let data = Data()
let timezone2 = TimezoneData.customObject(from: data)
XCTAssertNil(timezone2)
} }
func testDescription() { func testDescription() {
@ -118,6 +122,12 @@ class ClockerUnitTests: XCTestCase {
XCTAssertFalse(timezoneData.description.isEmpty) XCTAssertFalse(timezoneData.description.isEmpty)
XCTAssertFalse(timezoneData.debugDescription.isEmpty) XCTAssertFalse(timezoneData.debugDescription.isEmpty)
} }
func testHashing() {
let timezoneData = TimezoneData(with: california)
let hash = timezoneData.hash
XCTAssert(hash != -1)
}
func testDeletingATimezone() { func testDeletingATimezone() {
let defaults = UserDefaults.standard let defaults = UserDefaults.standard
@ -286,7 +296,7 @@ class ClockerUnitTests: XCTestCase {
XCTAssertFalse(dataObject.shouldShowSeconds(88)) XCTAssertFalse(dataObject.shouldShowSeconds(88))
} }
func testTimezone() { func testTimezoneRetrieval() {
let dataObject = TimezoneData(with: mumbai) let dataObject = TimezoneData(with: mumbai)
XCTAssertEqual(dataObject.timezone(), "Asia/Calcutta") XCTAssertEqual(dataObject.timezone(), "Asia/Calcutta")
@ -294,7 +304,6 @@ class ClockerUnitTests: XCTestCase {
dataObject.isSystemTimezone = true dataObject.isSystemTimezone = true
let autoupdatingTimezone = TimeZone.autoupdatingCurrent.identifier let autoupdatingTimezone = TimeZone.autoupdatingCurrent.identifier
XCTAssertEqual(dataObject.timezone(), autoupdatingTimezone) XCTAssertEqual(dataObject.timezone(), autoupdatingTimezone)
} }
func testFormattedLabel() { func testFormattedLabel() {

2
Clocker/CoreModelKit/Sources/CoreModelKit/TimezoneData.swift

@ -277,7 +277,7 @@ public class TimezoneData: NSObject, NSCoding {
} }
static func == (lhs: TimezoneData, rhs: TimezoneData) -> Bool { static func == (lhs: TimezoneData, rhs: TimezoneData) -> Bool {
return lhs.placeID == rhs.placeID return lhs.isEqual(rhs)
} }
public override func isEqual(_ object: Any?) -> Bool { public override func isEqual(_ object: Any?) -> Bool {

6
Clocker/CoreModelKit/Tests/CoreModelKitTests/TimezoneDataEqualityTests.swift

@ -14,7 +14,8 @@ class TimezoneDataEqualityTests: XCTestCase {
timezone2.timezoneID = "Africa/Banjul" timezone2.timezoneID = "Africa/Banjul"
timezone2.formattedAddress = "SameLabel" timezone2.formattedAddress = "SameLabel"
XCTAssertNotEqual(timezone1, timezone2) XCTAssertFalse(timezone1 == timezone2) // Test ==
XCTAssertNotEqual(timezone1, timezone2) // Test isEqual
} }
func testEqualityWhenTimezonesLabelsDiffer() { func testEqualityWhenTimezonesLabelsDiffer() {
@ -26,6 +27,7 @@ class TimezoneDataEqualityTests: XCTestCase {
timezone2.timezoneID = TimeZone.autoupdatingCurrent.identifier timezone2.timezoneID = TimeZone.autoupdatingCurrent.identifier
timezone2.formattedAddress = "DifferentLabel" timezone2.formattedAddress = "DifferentLabel"
XCTAssertFalse(timezone1 == timezone2)
XCTAssertNotEqual(timezone1, timezone2) XCTAssertNotEqual(timezone1, timezone2)
} }
@ -40,6 +42,7 @@ class TimezoneDataEqualityTests: XCTestCase {
timezone2.timezoneID = TimeZone.autoupdatingCurrent.identifier timezone2.timezoneID = TimeZone.autoupdatingCurrent.identifier
timezone2.formattedAddress = "DifferentLabel" timezone2.formattedAddress = "DifferentLabel"
XCTAssertTrue(timezone1 == timezone2)
XCTAssertEqual(timezone1, timezone2) XCTAssertEqual(timezone1, timezone2)
} }
@ -54,6 +57,7 @@ class TimezoneDataEqualityTests: XCTestCase {
timezone2.timezoneID = TimeZone.autoupdatingCurrent.identifier timezone2.timezoneID = TimeZone.autoupdatingCurrent.identifier
timezone2.formattedAddress = "DifferentLabel" timezone2.formattedAddress = "DifferentLabel"
XCTAssertFalse(timezone1 == timezone2)
XCTAssertNotEqual(timezone1, timezone2) XCTAssertNotEqual(timezone1, timezone2)
} }
} }

Loading…
Cancel
Save