1
1
mirror of https://github.com/qvacua/vimr.git synced 2024-12-29 16:56:40 +03:00
vimr/VimR/VimRTests/ArrayCommonsTest.swift

186 lines
3.8 KiB
Swift
Raw Normal View History

2016-11-26 19:59:55 +03:00
/**
* Tae Won Ha - http://taewon.de - @hataewon
* See LICENSE
*/
import XCTest
import Nimble
fileprivate class DummyToken: Comparable {
static func ==(left: DummyToken, right: DummyToken) -> Bool {
return left.value == right.value
}
static func <(left: DummyToken, right: DummyToken) -> Bool {
return left.value < right.value
}
let value: String
init(_ value: String) {
self.value = value
}
}
class ArrayCommonsTest: XCTestCase {
2017-05-02 23:18:09 +03:00
func testTuplesToDict() {
let tuples = [
(1, "1"),
(2, "2"),
(3, "3")
]
expect(tuplesToDict(tuples)).to(equal(
[
1: "1",
2: "2",
3: "3"
]
))
}
func testToDict() {
let array = [1, 2, 3]
expect(array.toDict { "\($0)" })
.to(equal(
[
1: "1",
2: "2",
3: "3"
]
))
}
func testRemovingDuplicatesPreservingFromBeginning() {
let array = [1, 2, 3, 4, 3, 3, 5, 3]
expect(array.removingDuplicatesPreservingFromBeginning()).to(equal([1, 2, 3, 4, 5]))
}
func testSubstituting1() {
2016-11-26 19:59:55 +03:00
let substitute = [
2017-05-02 23:18:09 +03:00
DummyToken("a0"),
DummyToken("a1"),
DummyToken("a2")
2016-11-26 19:59:55 +03:00
]
let array = [
2017-05-02 23:18:09 +03:00
DummyToken("b0"),
DummyToken("b1"),
DummyToken("a0"),
DummyToken("a1"),
DummyToken("b4"),
DummyToken("a2"),
2016-11-26 19:59:55 +03:00
]
let result = array.substituting(elements: substitute)
expect(result[2]).to(beIdenticalTo(substitute[0]))
expect(result[3]).to(beIdenticalTo(substitute[1]))
expect(result[5]).to(beIdenticalTo(substitute[2]))
expect(result).to(equal(array))
}
2017-05-02 23:18:09 +03:00
func testSubstituting2() {
2016-11-26 19:59:55 +03:00
let substitute = [
2017-05-02 23:18:09 +03:00
DummyToken("a0"),
DummyToken("a1"),
DummyToken("a2")
2016-11-26 19:59:55 +03:00
]
let array = [
2017-05-02 23:18:09 +03:00
DummyToken("a0"),
DummyToken("b0"),
DummyToken("a1"),
DummyToken("b1"),
DummyToken("a2"),
DummyToken("b4"),
2016-11-26 19:59:55 +03:00
]
let result = array.substituting(elements: substitute)
expect(result[0]).to(beIdenticalTo(substitute[0]))
expect(result[2]).to(beIdenticalTo(substitute[1]))
expect(result[4]).to(beIdenticalTo(substitute[2]))
expect(result).to(equal(array))
}
2017-05-02 23:18:09 +03:00
func testSubstituting3() {
2016-11-26 19:59:55 +03:00
let substitute = [
2017-05-02 23:18:09 +03:00
DummyToken("a0"),
DummyToken("a1"),
DummyToken("a2")
2016-11-26 19:59:55 +03:00
]
let array = [
2017-05-02 23:18:09 +03:00
DummyToken("b0"),
DummyToken("b1"),
DummyToken("b4"),
DummyToken("a0"),
DummyToken("a1"),
DummyToken("a2"),
2016-11-26 19:59:55 +03:00
]
let result = array.substituting(elements: substitute)
expect(result[3]).to(beIdenticalTo(substitute[0]))
expect(result[4]).to(beIdenticalTo(substitute[1]))
expect(result[5]).to(beIdenticalTo(substitute[2]))
expect(result).to(equal(array))
}
2017-05-02 23:18:09 +03:00
func testSubstituting4() {
2016-11-26 19:59:55 +03:00
let substitute = [
2017-05-02 23:18:09 +03:00
DummyToken("a0"),
DummyToken("a1"),
DummyToken("a2")
2016-11-26 19:59:55 +03:00
]
let array = [
2017-05-02 23:18:09 +03:00
DummyToken("a0"),
DummyToken("a1"),
DummyToken("a2"),
DummyToken("b0"),
DummyToken("b1"),
DummyToken("b4"),
2016-11-26 19:59:55 +03:00
]
let result = array.substituting(elements: substitute)
expect(result[0]).to(beIdenticalTo(substitute[0]))
expect(result[1]).to(beIdenticalTo(substitute[1]))
expect(result[2]).to(beIdenticalTo(substitute[2]))
expect(result).to(equal(array))
}
2017-05-02 23:18:09 +03:00
func testSubstituting5() {
2016-11-26 19:59:55 +03:00
let substitute = [
2017-05-02 23:18:09 +03:00
DummyToken("a0"),
DummyToken("something else"),
DummyToken("a1"),
DummyToken("a2"),
2016-11-26 19:59:55 +03:00
]
let array = [
2017-05-02 23:18:09 +03:00
DummyToken("a0"),
DummyToken("b0"),
DummyToken("a1"),
DummyToken("b1"),
DummyToken("a2"),
DummyToken("b4"),
2016-11-26 19:59:55 +03:00
]
let result = array.substituting(elements: substitute)
expect(result[0]).to(beIdenticalTo(substitute[0]))
expect(result[2]).to(beIdenticalTo(substitute[2]))
expect(result[4]).to(beIdenticalTo(substitute[3]))
expect(result).to(equal(array))
}
}