mirror of
https://github.com/neon443/StickerSlack.git
synced 2026-11-30 20:54:51 +00:00
update tests
This commit is contained in:
3 files changed
+63
-43
No files matched your search
@@ -119,6 +119,8 @@
|
|||||||
A9EB724D2EB94A6B00658CEB /* TrieTestingView.swift in Sources */ = {isa = PBXBuildFile; fileRef = A9EB724C2EB94A6B00658CEB /* TrieTestingView.swift */; };
|
A9EB724D2EB94A6B00658CEB /* TrieTestingView.swift in Sources */ = {isa = PBXBuildFile; fileRef = A9EB724C2EB94A6B00658CEB /* TrieTestingView.swift */; };
|
||||||
A9EB724F2EB94A6B00658CEB /* 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 */; };
|
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 */
|
/* End PBXBuildFile section */
|
||||||
|
|
||||||
/* Begin PBXContainerItemProxy section */
|
/* Begin PBXContainerItemProxy section */
|
||||||
@@ -689,6 +691,7 @@
|
|||||||
A9A7A4402F6835F800BB84C6 /* Trending.swift in Sources */,
|
A9A7A4402F6835F800BB84C6 /* Trending.swift in Sources */,
|
||||||
A9BE30F72F5B011A00A57668 /* StickerProtocol.swift in Sources */,
|
A9BE30F72F5B011A00A57668 /* StickerProtocol.swift in Sources */,
|
||||||
A9BE30FC2F5B03F400A57668 /* Sticker.swift in Sources */,
|
A9BE30FC2F5B03F400A57668 /* Sticker.swift in Sources */,
|
||||||
|
A9EC46AE2F6D9E5800E066E6 /* StickerType.swift in Sources */,
|
||||||
A9B9A82F2EB2CCED004C9245 /* EmojiHoarder.swift in Sources */,
|
A9B9A82F2EB2CCED004C9245 /* EmojiHoarder.swift in Sources */,
|
||||||
A9CD6C3B2EDDE6B500B7F421 /* EmojiPack.swift in Sources */,
|
A9CD6C3B2EDDE6B500B7F421 /* EmojiPack.swift in Sources */,
|
||||||
A921C2E32ED071C900E57B1A /* ListRow.swift in Sources */,
|
A921C2E32ED071C900E57B1A /* ListRow.swift in Sources */,
|
||||||
@@ -698,6 +701,7 @@
|
|||||||
A9EB724D2EB94A6B00658CEB /* TrieTestingView.swift in Sources */,
|
A9EB724D2EB94A6B00658CEB /* TrieTestingView.swift in Sources */,
|
||||||
A9BBC51A2EB8FA4500FFE82F /* ViewModifiers.swift in Sources */,
|
A9BBC51A2EB8FA4500FFE82F /* ViewModifiers.swift in Sources */,
|
||||||
A955B3ED2EC22C4A00E1732D /* DownloadedView.swift in Sources */,
|
A955B3ED2EC22C4A00E1732D /* DownloadedView.swift in Sources */,
|
||||||
|
A9EC46AD2F6D9E4600E066E6 /* Hoarder.swift in Sources */,
|
||||||
A9A7A4682F6AA17C00BB84C6 /* Int.swift in Sources */,
|
A9A7A4682F6AA17C00BB84C6 /* Int.swift in Sources */,
|
||||||
A9C172DC2EB8C9AC008A7885 /* Trie.swift in Sources */,
|
A9C172DC2EB8C9AC008A7885 /* Trie.swift in Sources */,
|
||||||
A957C1752ECCE2CE00EA3EE9 /* SettingsView.swift in Sources */,
|
A957C1752ECCE2CE00EA3EE9 /* SettingsView.swift in Sources */,
|
||||||
|
|||||||
@@ -24,7 +24,8 @@
|
|||||||
{
|
{
|
||||||
"name" : "PerformanceTests",
|
"name" : "PerformanceTests",
|
||||||
"testFunctions" : [
|
"testFunctions" : [
|
||||||
"downloadAll()"
|
"downloadAll()",
|
||||||
|
"fakeDownloadAllStickers()"
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
|
|||||||
@@ -14,27 +14,21 @@ struct StickerSlackTests {
|
|||||||
@Test func MSStickerValidation() async throws {
|
@Test func MSStickerValidation() async throws {
|
||||||
let goodEmoji = Emoji(
|
let goodEmoji = Emoji(
|
||||||
name: "name",
|
name: "name",
|
||||||
url: URL(string: "https://neon443.github.io/images/fav.ico")!,
|
url: URL(string: "https://neon443.xyz/images/fav.ico")!,
|
||||||
id: UUID(uuidString: "0c48f4c3-1c63-41ed-96db-909e50e35dfc")!
|
id: "0c48f4c3-1c63-41ed-96db-909e50e35dfc"
|
||||||
)
|
)
|
||||||
try! await goodEmoji.downloadImage()
|
try! await goodEmoji.downloadImage()
|
||||||
#expect(goodEmoji.sticker!.validate(), "should be true")
|
#expect(goodEmoji.msSticker!.validate(), "should be true")
|
||||||
|
|
||||||
let badEmoji = Emoji(
|
let badEmoji = Emoji(
|
||||||
name: "160chars:shttps://emoji.slack-edge.com/T0266FRGM/100906/ddeb22d813b83b0f.pngs,sexpirationfds2025-10-28T08:00:02.011Zs},{gtypeh:jemojieeeidggg9cab2003-ad74-492a-",
|
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")!,
|
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()
|
try! await badEmoji.downloadImage()
|
||||||
#expect(goodEmoji.sticker!.validate(), "should be true")
|
#expect(goodEmoji.msSticker!.validate(), "should be true")
|
||||||
badEmoji.deleteImage()
|
badEmoji.deleteImage()
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test func deleteAllEmojis() async throws {
|
|
||||||
let performanceTests = PerformanceTests(hoarder: .shared)
|
|
||||||
try! await performanceTests.fakeDownloadAllStickers()
|
|
||||||
await hoarder.deleteAllStickers()
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
struct PerformanceTests {
|
struct PerformanceTests {
|
||||||
@@ -43,7 +37,7 @@ struct PerformanceTests {
|
|||||||
@Test func stickerConversion() async throws {
|
@Test func stickerConversion() async throws {
|
||||||
// Write your test here and use APIs like `#expect(...)` to check expected conditions.
|
// Write your test here and use APIs like `#expect(...)` to check expected conditions.
|
||||||
for emoji in hoarder.emojis {
|
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 {
|
@Test func downloadAll() async throws {
|
||||||
let downloadedEmojisBefore = hoarder.emojis.filter { $0.isLocal }.map { $0.id }
|
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 {
|
func doThing(on emoji: Emoji, i: inout Int) async throws {
|
||||||
do {
|
do {
|
||||||
guard !emoji.isLocal else { return }
|
guard !emoji.isLocal else { return }
|
||||||
async let (data, _) = try URLSession.shared.data(from: emoji.remoteImageURL)
|
async let (data, _) = try URLSession.shared.data(from: emoji.remoteImageURL)
|
||||||
try! await data.write(to: emoji.localImageURL)
|
try! await data.write(to: emoji.localImageURL)
|
||||||
let _ = emoji.sticker?.validate()
|
let _ = emoji.msSticker?.validate()
|
||||||
i+=1
|
i+=1
|
||||||
print("\(i)/\(hoarder.emojis.count) \(emoji.name)")
|
print("\(i)/\(hoarder.emojis.count) \(emoji.name)")
|
||||||
} catch {
|
} catch {
|
||||||
@@ -113,34 +99,26 @@ struct PerformanceTests {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test func fakeDownloadAllStickers() async throws {
|
// @Test func fakeDownloadAllStickers() async throws {
|
||||||
await withDiscardingTaskGroup { group in
|
// await withDiscardingTaskGroup { group in
|
||||||
for emoji in hoarder.emojis {
|
// for emoji in hoarder.emojis {
|
||||||
group.addTask {
|
// group.addTask {
|
||||||
try! Data().write(to: emoji.localImageURL)
|
// try! Data().write(to: emoji.localImageURL)
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
|
|
||||||
@Test func deleteAllImages() async throws {
|
@Test func deleteAllImages() async throws {
|
||||||
try! await fakeDownloadAllStickers()
|
// try! await fakeDownloadAllStickers()
|
||||||
await hoarder.deleteAllStickers()
|
await hoarder.deleteAllStickers()
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test func buildTrie() async throws {
|
@Test func buildTrie() async throws {
|
||||||
hoarder.resetTrie()
|
hoarder.resetAllIndexes()
|
||||||
hoarder.buildTrie()
|
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 {
|
@Test func testIsLocal() async throws {
|
||||||
for emoji in hoarder.emojis {
|
for emoji in hoarder.emojis {
|
||||||
let x = emoji.isLocal
|
let x = emoji.isLocal
|
||||||
@@ -152,4 +130,41 @@ struct PerformanceTests {
|
|||||||
let x = hoarder.downloadedStickers.contains(emoji.name)
|
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
|
||||||
|
}
|
||||||
}
|
}
|
||||||