-
Notifications
You must be signed in to change notification settings - Fork 39
/
Copy pathNumberParsingTests.swift
75 lines (56 loc) · 2.52 KB
/
NumberParsingTests.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
//
// SVGPathTests.swift
// SVGPathTests
//
// Created by Tim Wood on 1/21/15.
// Copyright (c) 2015 Tim Wood. All rights reserved.
//
import XCTest
import SVGPath
class NumberParsingTests: XCTestCase {
func testSpaceSeparatedInts() {
let actual:[CGFloat] = SVGPath.parseNumbers("1 2 3 4")
let expect:[CGFloat] = [1.0, 2.0, 3.0, 4.0]
XCTAssertEqual(actual, expect, "Should parse space separated ints")
}
func testCommaSeparatedInts() {
let actual:[CGFloat] = SVGPath.parseNumbers("1,2,3,4")
let expect:[CGFloat] = [1.0, 2.0, 3.0, 4.0]
XCTAssertEqual(actual, expect, "Should parse comma separated ints")
}
func testMinusSeparatedInts() {
let actual:[CGFloat] = SVGPath.parseNumbers("-1-2-3-4")
let expect:[CGFloat] = [-1.0, -2.0, -3.0, -4.0]
XCTAssertEqual(actual, expect, "Should parse minus separated ints")
}
func testSpaceSeparatedFloats() {
let actual:[CGFloat] = SVGPath.parseNumbers("1.5 2.6 3.7 4.8")
let expect:[CGFloat] = [1.5, 2.6, 3.7, 4.8]
XCTAssertEqual(actual, expect, "Should parse space separated floats")
}
func testCommaSeparatedFloats() {
let actual:[CGFloat] = SVGPath.parseNumbers("1.5,2.6,3.7,4.8")
let expect:[CGFloat] = [1.5, 2.6, 3.7, 4.8]
XCTAssertEqual(actual, expect, "Should parse comma separated floats")
}
func testMinusSeparatedFloats() {
let actual:[CGFloat] = SVGPath.parseNumbers("-1.5-2.6-3.7-4.8")
let expect:[CGFloat] = [-1.5, -2.6, -3.7, -4.8]
XCTAssertEqual(actual, expect, "Should parse minus separated floats")
}
func testSpaceSeparatedExponent() {
let actual:[CGFloat] = SVGPath.parseNumbers("1e1 1e2 1E3 1E4")
let expect:[CGFloat] = [10.0, 100.0, 1000.0, 10000.0]
XCTAssertEqual(actual, expect, "Should use e or E for the exponent")
}
func testNonSeparatingExponent() {
let actual:[CGFloat] = SVGPath.parseNumbers("1e-5-1e-5,1E-5-1E-5")
let expect:[CGFloat] = [0.00001, -0.00001, 0.00001, -0.00001]
XCTAssertEqual(actual, expect, "Should not split on the minus from an exponent")
}
func testNegativeNumbersFollowingSpaces() {
let actual:[CGFloat] = SVGPath.parseNumbers("-2.1 1 -1 2.1 -1 3.4")
let expect:[CGFloat] = [-2.1, 1, -1, 2.1, -1, 3.4]
XCTAssertEqual(actual, expect, "Should allow spaces before negative numbers")
}
}