Skip to content

Commit 33a5a4b

Browse files
Backfill some tests
1 parent 1fcf56b commit 33a5a4b

File tree

7 files changed

+161
-17
lines changed

7 files changed

+161
-17
lines changed

AllTests.xctestplan

Lines changed: 5 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -16,30 +16,20 @@
1616
"identifier" : "950402CE2D4D522100F51903",
1717
"name" : "Alidade"
1818
},
19-
{
20-
"containerPath" : "container:MCMaps.xcodeproj",
21-
"identifier" : "950402DF2D4D522200F51903",
22-
"name" : "MCMapsTests"
23-
},
2419
{
2520
"containerPath" : "container:AlidadeUI",
2621
"identifier" : "AlidadeUI",
2722
"name" : "AlidadeUI"
2823
},
29-
{
30-
"containerPath" : "container:MCMapFormat",
31-
"identifier" : "MCMapFormat",
32-
"name" : "MCMapFormat"
33-
},
34-
{
35-
"containerPath" : "container:MCMapFormat",
36-
"identifier" : "MCMapFormatTests",
37-
"name" : "MCMapFormatTests"
38-
},
3924
{
4025
"containerPath" : "container:AlidadeUI",
4126
"identifier" : "AlidadeUITests",
4227
"name" : "AlidadeUITests"
28+
},
29+
{
30+
"containerPath" : "container:MCMaps.xcodeproj",
31+
"identifier" : "950402DF2D4D522200F51903",
32+
"name" : "MCMapsTests"
4333
}
4434
]
4535
},

MCMaps/Shared/Models/Document/IndexedPinCollection.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ import MCMap
2929
struct IndexedPinCollection {
3030
fileprivate typealias InternalContainer = [CartographyMapPin]
3131
/// A structure representing an element in the collection.
32-
struct Element: Identifiable {
32+
struct Element: Identifiable, Equatable, Hashable {
3333
/// A unique identifier for the element.
3434
var id: Int { index }
3535

MCMaps/Shared/Models/RandomAccessDictionary.swift

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,9 +67,15 @@ extension RandomAccessDictionary: Collection {
6767
}
6868
}
6969

70+
extension RandomAccessDictionary.Element: Equatable where Key: Equatable, Value: Equatable {}
71+
7072
extension RandomAccessDictionary: RandomAccessCollection {
73+
// NOTE: This is more or less a dummy function, because dictionaries are unordered!
7174
func index(before index: Index) -> Index {
72-
dictionary.index(index, offsetBy: -1)
75+
let offset = self.distance(from: startIndex, to: index)
76+
return dictionary.index(
77+
after: dictionary.index(dictionary.startIndex, offsetBy: offset - 1)
78+
)
7379
}
7480
}
7581

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
//
2+
// MinecraftWorldTests.swift
3+
// MCMaps
4+
//
5+
// Created by Marquis Kurt on 04-08-2025.
6+
//
7+
8+
import CubiomesKit
9+
import MCMap
10+
import Testing
11+
12+
@testable import Alidade
13+
14+
struct MinecraftWorldTests {
15+
@Test func worldInitFromSettings() async throws {
16+
let worldSettings = MCMapManifestWorldSettings(version: "1.21", seed: 123)
17+
let world = try MinecraftWorld(worldSettings: worldSettings)
18+
19+
#expect(world.version == MC_1_21)
20+
#expect(world.seed == 123)
21+
}
22+
}
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
//
2+
// IndexedPinCollectionTests.swift
3+
// MCMaps
4+
//
5+
// Created by Marquis Kurt on 04-08-2025.
6+
//
7+
8+
import Foundation
9+
import MCMap
10+
import Testing
11+
12+
@testable import Alidade
13+
14+
struct IndexedPinCollectionTests {
15+
var myPins = [
16+
CartographyMapPin(named: "Spawn", at: .zero),
17+
CartographyMapPin(named: "Another Pin", at: CGPoint(x: 132, y: 132)),
18+
CartographyMapPin(named: "Hotel Letztes Jahr", at: CGPoint(x: 1847, y: 1963))
19+
]
20+
21+
@Test func indexedPinCollectionConformances() async throws {
22+
let collection = IndexedPinCollection(myPins)
23+
#expect(collection.count == myPins.count)
24+
#expect(collection.startIndex == myPins.startIndex)
25+
#expect(collection.endIndex == myPins.endIndex)
26+
#expect(collection.index(after: collection.startIndex) == myPins.index(after: myPins.startIndex))
27+
28+
let first = try #require(collection.first)
29+
#expect(first == IndexedPinCollection.Element(index: 0, content: myPins[0]))
30+
}
31+
32+
@Test func indexedPinCollectionHashable() async throws {
33+
let collection = IndexedPinCollection(myPins)
34+
let hashValue = collection.hashValue
35+
#expect(hashValue != 0)
36+
}
37+
38+
@Test func indexPinCollectionCodable() async throws {
39+
let collection = IndexedPinCollection(myPins)
40+
let jsonEncoder = JSONEncoder()
41+
let encoded = try jsonEncoder.encode(collection)
42+
43+
#expect(!encoded.isEmpty)
44+
45+
let jsonDecoder = JSONDecoder()
46+
let backToCollection = try jsonDecoder.decode(IndexedPinCollection.self, from: encoded)
47+
#expect(backToCollection == collection)
48+
49+
#if swift(>=6.2)
50+
Attachment.record(encoded)
51+
#endif
52+
}
53+
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
//
2+
// RandomAccessDictionaryTests.swift
3+
// MCMaps
4+
//
5+
// Created by Marquis Kurt on 04-08-2025.
6+
//
7+
8+
import Foundation
9+
import Testing
10+
11+
@testable import Alidade
12+
13+
struct RandomAccessDictionaryTests {
14+
let originalDict = ["foo": 1, "bar": 13, "baz": 1847]
15+
16+
@Test func collectionConformances() async throws {
17+
let rad = RandomAccessDictionary(originalDict)
18+
19+
#expect(rad.count == 3)
20+
#expect(rad.startIndex == originalDict.startIndex)
21+
#expect(rad.endIndex == originalDict.endIndex)
22+
#expect(rad.index(after: rad.startIndex) == originalDict.index(after: originalDict.startIndex))
23+
}
24+
25+
@Test func randomAccessConformances() async throws {
26+
let rad = RandomAccessDictionary(originalDict)
27+
28+
#expect(rad.index(before: rad.endIndex).hashValue != 0)
29+
}
30+
}
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
//
2+
// CartographyClockTests.swift
3+
// MCMaps
4+
//
5+
// Created by Marquis Kurt on 04-08-2025.
6+
//
7+
8+
import Combine
9+
import Foundation
10+
import Testing
11+
12+
@testable import Alidade
13+
14+
struct CartographyClockTests {
15+
@Test func clockInitialValues() async throws {
16+
let clock = CartographyClock()
17+
18+
#expect(clock.realtime.upstream.interval == 0.5)
19+
#expect(clock.realtime.upstream.mode == .common)
20+
#expect(clock.realtime.upstream.runLoop == RunLoop.main)
21+
22+
// Verify that we've made this timer infinite so as to never execute.
23+
#expect(clock.bluemap.upstream.interval == .greatestFiniteMagnitude)
24+
}
25+
26+
@Test func clockSetup() async throws {
27+
let clock = CartographyClock()
28+
clock.setup(timer: .bluemap, at: 100)
29+
clock.start(timer: .bluemap)
30+
31+
#expect(clock.bluemap.upstream.interval == 100)
32+
}
33+
34+
@Test func clockDestroy() async throws {
35+
let clock = CartographyClock()
36+
clock.setup(timer: .bluemap, at: 100)
37+
clock.start(timer: .bluemap)
38+
39+
try await Task.sleep(for: .seconds(1))
40+
41+
clock.stop(timer: .bluemap)
42+
}
43+
}

0 commit comments

Comments
 (0)