|
| 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 | +} |
0 commit comments