-
Notifications
You must be signed in to change notification settings - Fork 215
/
Medium_093_Restore_IP_Addresses_Test.swift
76 lines (74 loc) · 2.63 KB
/
Medium_093_Restore_IP_Addresses_Test.swift
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
//
// Medium_093_Restore_IP_Addresses_Test.swift
// Solutions
//
// Created by Di Wu on 11/2/15.
// Copyright © 2015 diwu. All rights reserved.
//
import XCTest
class Medium_093_Restore_IP_Addresses_Test: XCTestCase, SolutionsTestCase {
func test_001() {
let input: String = "25525511135"
let expected: [String] = [
"255.255.11.135",
"255.255.111.35"
]
asyncHelper(input: input, expected: expected)
}
func test_002() {
let input: String = "010010"
let expected: [String] = [
"0.10.0.10",
"0.100.1.0",
]
asyncHelper(input: input, expected: expected)
}
func test_003() {
let input: String = "1111"
let expected: [String] = [
"1.1.1.1"
]
asyncHelper(input: input, expected: expected)
}
func test_004() {
let input: String = "11111"
let expected: [String] = [
"11.1.1.1",
"1.11.1.1",
"1.1.11.1",
"1.1.1.11",
]
asyncHelper(input: input, expected: expected)
}
func test_005() {
let input: String = "01001000"
let expected: [String] = [
"0.100.100.0"
]
asyncHelper(input: input, expected: expected)
}
func test_006() {
let input: String = "256000"
let expected: [String] = [
"25.60.0.0"
]
asyncHelper(input: input, expected: expected)
}
private func asyncHelper(input: String, expected: [String]) {
weak var expectation: XCTestExpectation? = self.expectation(description:timeOutName())
serialQueue().async(execute: { () -> Void in
let result_swift: [String] = Medium_093_Restore_IP_Addresses.restoreIpAddresses(input)
let result_objc: [String] = ObjC_Medium_093_Restore_IP_Addresses.restoreIpAddresses(input)
assertHelper(NSSet.init(array: result_swift) == NSSet.init(array: expected), problemName:self.problemName(), input: input, resultValue: result_swift, expectedValue: expected)
assertHelper(NSSet.init(array: result_objc) == NSSet.init(array: expected), problemName:self.problemName(), input: input, resultValue: result_objc, expectedValue: expected)
if let unwrapped = expectation {
unwrapped.fulfill()
}
})
waitForExpectations(timeout:timeOut()) { (error: Error?) -> Void in
if error != nil {
assertHelper(false, problemName:self.problemName(), input: input, resultValue:self.timeOutName(), expectedValue: expected)
}
}
}
}