From 78477eec6a1393eaf84ef2192332d738b81bede6 Mon Sep 17 00:00:00 2001 From: neon443 <69979447+neon443@users.noreply.github.com> Date: Sat, 21 Mar 2026 11:07:06 +0000 Subject: [PATCH] update tests --- StickerSlack.xcodeproj/project.pbxproj | 4 + StickerSlackTests/StickerSlack.xctestplan | 3 +- StickerSlackTests/StickerSlackTests.swift | 99 +++++++++++++---------- 3 files changed, 63 insertions(+), 43 deletions(-) diff --git a/StickerSlack.xcodeproj/project.pbxproj b/StickerSlack.xcodeproj/project.pbxproj index dc40fd5..cc9649b 100644 --- a/StickerSlack.xcodeproj/project.pbxproj +++ b/StickerSlack.xcodeproj/project.pbxproj @@ -119,6 +119,8 @@ A9EB724D2EB94A6B00658CEB /* TrieTestingView.swift in Sources */ = {isa = PBXBuildFile; fileRef = A9EB724C2EB94A6B00658CEB /* TrieTestingView.swift */; }; A9EB724F2EB94A6B00658CEB /* TrieTestingView.swift in Sources */ = {isa = PBXBuildFile; fileRef = A9EB724C2EB94A6B00658CEB /* TrieTestingView.swift */; }; A9EB72502EB94FAD00658CEB /* EmojiPreview.swift in Sources */ = {isa = PBXBuildFile; fileRef = A9773C2E2EA54AF000F3B753 /* EmojiPreview.swift */; }; + A9EC46AD2F6D9E4600E066E6 /* Hoarder.swift in Sources */ = {isa = PBXBuildFile; fileRef = A9BE30FD2F5FA47100A57668 /* Hoarder.swift */; }; + A9EC46AE2F6D9E5800E066E6 /* StickerType.swift in Sources */ = {isa = PBXBuildFile; fileRef = A9BE30EB2F5AFE1E00A57668 /* StickerType.swift */; }; /* End PBXBuildFile section */ /* Begin PBXContainerItemProxy section */ @@ -689,6 +691,7 @@ A9A7A4402F6835F800BB84C6 /* Trending.swift in Sources */, A9BE30F72F5B011A00A57668 /* StickerProtocol.swift in Sources */, A9BE30FC2F5B03F400A57668 /* Sticker.swift in Sources */, + A9EC46AE2F6D9E5800E066E6 /* StickerType.swift in Sources */, A9B9A82F2EB2CCED004C9245 /* EmojiHoarder.swift in Sources */, A9CD6C3B2EDDE6B500B7F421 /* EmojiPack.swift in Sources */, A921C2E32ED071C900E57B1A /* ListRow.swift in Sources */, @@ -698,6 +701,7 @@ A9EB724D2EB94A6B00658CEB /* TrieTestingView.swift in Sources */, A9BBC51A2EB8FA4500FFE82F /* ViewModifiers.swift in Sources */, A955B3ED2EC22C4A00E1732D /* DownloadedView.swift in Sources */, + A9EC46AD2F6D9E4600E066E6 /* Hoarder.swift in Sources */, A9A7A4682F6AA17C00BB84C6 /* Int.swift in Sources */, A9C172DC2EB8C9AC008A7885 /* Trie.swift in Sources */, A957C1752ECCE2CE00EA3EE9 /* SettingsView.swift in Sources */, diff --git a/StickerSlackTests/StickerSlack.xctestplan b/StickerSlackTests/StickerSlack.xctestplan index 132c571..05eb0f8 100644 --- a/StickerSlackTests/StickerSlack.xctestplan +++ b/StickerSlackTests/StickerSlack.xctestplan @@ -24,7 +24,8 @@ { "name" : "PerformanceTests", "testFunctions" : [ - "downloadAll()" + "downloadAll()", + "fakeDownloadAllStickers()" ] } ] diff --git a/StickerSlackTests/StickerSlackTests.swift b/StickerSlackTests/StickerSlackTests.swift index dec9317..b402a81 100644 --- a/StickerSlackTests/StickerSlackTests.swift +++ b/StickerSlackTests/StickerSlackTests.swift @@ -14,27 +14,21 @@ struct StickerSlackTests { @Test func MSStickerValidation() async throws { let goodEmoji = Emoji( name: "name", - url: URL(string: "https://neon443.github.io/images/fav.ico")!, - id: UUID(uuidString: "0c48f4c3-1c63-41ed-96db-909e50e35dfc")! + url: URL(string: "https://neon443.xyz/images/fav.ico")!, + id: "0c48f4c3-1c63-41ed-96db-909e50e35dfc" ) try! await goodEmoji.downloadImage() - #expect(goodEmoji.sticker!.validate(), "should be true") + #expect(goodEmoji.msSticker!.validate(), "should be true") let badEmoji = Emoji( name: "160chars:shttps://emoji.slack-edge.com/T0266FRGM/100906/ddeb22d813b83b0f.pngs,sexpirationfds2025-10-28T08:00:02.011Zs},{gtypeh:jemojieeeidggg9cab2003-ad74-492a-", url: URL(string: "https://files.catbox.moe/ifh710.png")!, - id: UUID(uuidString: "0c48f4c3-1c63-41ed-96db-909e50e35dfc")! + id: "0c48f4c3-1c63-41ed-96db-909e50e35dfc" ) try! await badEmoji.downloadImage() - #expect(goodEmoji.sticker!.validate(), "should be true") + #expect(goodEmoji.msSticker!.validate(), "should be true") badEmoji.deleteImage() } - - @Test func deleteAllEmojis() async throws { - let performanceTests = PerformanceTests(hoarder: .shared) - try! await performanceTests.fakeDownloadAllStickers() - await hoarder.deleteAllStickers() - } } struct PerformanceTests { @@ -43,7 +37,7 @@ struct PerformanceTests { @Test func stickerConversion() async throws { // Write your test here and use APIs like `#expect(...)` to check expected conditions. for emoji in hoarder.emojis { - let _ = emoji.sticker + let _ = emoji.msSticker } } @@ -53,16 +47,7 @@ struct PerformanceTests { } } - @Test func filteringEmojis() async throws { - let searchQueries = ["heavysob", "yay", "afsdjk", "afhjskf", "g4", "aqua-osx", "neotunes", "", "", ""] - for query in searchQueries { - print(query) - hoarder.filteredEmojis = [] - hoarder.filterEmojis(by: query) - print(hoarder.filteredEmojis.count) - } - } - + /* @Test func downloadAll() async throws { let downloadedEmojisBefore = hoarder.emojis.filter { $0.isLocal }.map { $0.id } @@ -99,13 +84,14 @@ struct PerformanceTests { } } } + */ func doThing(on emoji: Emoji, i: inout Int) async throws { do { guard !emoji.isLocal else { return } async let (data, _) = try URLSession.shared.data(from: emoji.remoteImageURL) try! await data.write(to: emoji.localImageURL) - let _ = emoji.sticker?.validate() + let _ = emoji.msSticker?.validate() i+=1 print("\(i)/\(hoarder.emojis.count) \(emoji.name)") } catch { @@ -113,34 +99,26 @@ struct PerformanceTests { } } - @Test func fakeDownloadAllStickers() async throws { - await withDiscardingTaskGroup { group in - for emoji in hoarder.emojis { - group.addTask { - try! Data().write(to: emoji.localImageURL) - } - } - } - } +// @Test func fakeDownloadAllStickers() async throws { +// await withDiscardingTaskGroup { group in +// for emoji in hoarder.emojis { +// group.addTask { +// try! Data().write(to: emoji.localImageURL) +// } +// } +// } +// } @Test func deleteAllImages() async throws { - try! await fakeDownloadAllStickers() +// try! await fakeDownloadAllStickers() await hoarder.deleteAllStickers() } @Test func buildTrie() async throws { - hoarder.resetTrie() + hoarder.resetAllIndexes() hoarder.buildTrie() } - @Test func testSearching() async throws { - try! await buildTrie() - let terms = ["h", "j", "s", "2", "heavysob", "hs", "asjasdklf", "a", "w", "t", "h", "z", "b", "c", "m", "n"] - for term in terms { - let _ = hoarder.trie.search(prefix: term) - } - } - @Test func testIsLocal() async throws { for emoji in hoarder.emojis { let x = emoji.isLocal @@ -152,4 +130,41 @@ struct PerformanceTests { let x = hoarder.downloadedStickers.contains(emoji.name) } } + + @Test func testSearching() async throws { + try await testSearchingExactly() + try await testSearchingFor() + try await testSearchingPrefixes() + } + @Test func testSearchingFor() async throws { + let queries = hoarder.emojis.choose(10_000).map { $0.name } + for query in queries { + let _ = hoarder.trie.search(for: query) + } + } + @Test func testSearchingExactly() async throws { + let queries = hoarder.emojis.choose(10_000).map { $0.name } + for query in queries { + let _ = hoarder.trie.search(exactly: query) + } + } + @Test func testSearchingPrefixes() async throws { + let queries = hoarder.emojis.choose(10_000).map { $0.name } + for query in queries { + let _ = hoarder.trie.search(prefix: query) + } + } +} + +extension Array { + func choose(_ x: Int) -> Self { + var x = x + var result: Self = [] + while x != 0 { + guard let randElement = self.randomElement() else { continue } + result.append(randElement) + x-=1 + } + return result + } }