Skip to content

Commit

Permalink
More stats tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
alex-kulcsar committed Jul 1, 2024
1 parent ec0cc7f commit d8fae79
Show file tree
Hide file tree
Showing 4 changed files with 295 additions and 2 deletions.
4 changes: 4 additions & 0 deletions main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@ if (!DeleteTests.run()) {
allPassed = false
}

if (!StatsTests.run()) {
allPassed = false
}

// Show summary.
if (allPassed) {
game.splash("All tests passed!")
Expand Down
5 changes: 3 additions & 2 deletions pxt.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"version": "0.0.0",
"dependencies": {
"device": "*",
"pxt-fast-ternary-string-set": "github:robo-technical-group/pxt-fast-ternary-string-set#v1.2.1"
"pxt-fast-ternary-string-set": "github:robo-technical-group/pxt-fast-ternary-string-set#v1.3.1"
},
"files": [
"main.ts",
Expand All @@ -12,7 +12,8 @@
"clear.ts",
"short-english-list.ts",
"size.ts",
"delete.ts"
"delete.ts",
"stats.ts"
],
"testDependencies": {},
"targetVersions": {
Expand Down
77 changes: 77 additions & 0 deletions size.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,83 @@ namespace SizeTests {
game.splash("Size test 2d failed.")
allPassed = false
}

// size with empty string.
test = new TernaryStringSet()
if (test.size != 0) {
game.splash("Size test 3a failed.")
allPassed = false
}
test.add("")
if (test.size != 1) {
game.splash("Size test 3b failed.")
allPassed = false
}
test.add("")
if (test.size != 1) {
game.splash("Size test 3c failed.")
allPassed = false
}
test.delete("")
if (test.size != 0) {
game.splash("Size test 3d failed.")
allPassed = false
}
test.delete("")
if (test.size != 0) {
game.splash("Size test 3e failed.")
allPassed = false
}
test.add("")
if (test.size != 1) {
game.splash("Size test 3f failed.")
allPassed = false
}
test.add("whale")
if (test.size != 2) {
game.splash("Size test 3g failed.")
allPassed = false
}

// size accurate after addAll() of word list.
test = new TernaryStringSet()
if (test.size != 0) {
game.splash("Size test 4a failed.")
allPassed = false
}
test.addAll(ShortEnglishList.words)
let len: number = ShortEnglishList.words.length
if (test.size != len) {
game.splash("Size test 4b failed.")
allPassed = false
}
// test.balance()
if (test.size != len) {
game.splash("Size test 4c failed.")
allPassed = false
}
// test.compact()
if (test.size != len) {
game.splash("Size test 4d failed.")
allPassed = false
}
let i: number = 0
for (const el of ShortEnglishList.words) {
test.delete(el)
i++
if (test.size != len- i){
game.splash(`Size test 4e failed at count ${i}.`)
allPassed = false
}
}
for (const el of ShortEnglishList.words) {
test.delete(el)
if (test.size != 0) {
game.splash(`Size test 4f failed at word ${el}.`)
allPassed = false
}
}

return allPassed
}
}
211 changes: 211 additions & 0 deletions stats.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,211 @@
namespace StatsTests {
export function run(): boolean {
let test: TernaryStringSet
let stats: TernaryTreeStats
let allPassed: boolean = true

// Trivial stats for empty set.
test = new TernaryStringSet()
stats = test.stats
if (stats.size != 0) {
game.splash("Stats test 1a failed.")
allPassed = false
}
if (stats.nodes != 0) {
game.splash("Stats test 1b failed.")
allPassed = false
}
if (stats.depth != 0) {
game.splash("Stats test 1c failed.")
allPassed = false
}
if (stats.breadth.length != 0) {
game.splash("Stats test 1d failed.")
allPassed = false
}
if (stats.minCodePoint != 0) {
game.splash("Stats test 1e failed.")
allPassed = false
}
if (stats.maxCodePoint != 0) {
game.splash("Stats test 1f failed.")
allPassed = false
}
if (stats.surrogates != 0) {
game.splash("Stats test 1g failed.")
allPassed = false
}

// Empty string increments size but adds no nodes.
test.add("")
stats = test.stats
if (stats.size != 1) {
game.splash("Stats test 2a failed.")
allPassed = false
}
if (stats.nodes != 0) {
game.splash("Stats test 2b failed.")
allPassed = false
}
if (stats.depth != 0) {
game.splash("Stats test 2c failed.")
allPassed = false
}
if (stats.breadth.length != 0) {
game.splash("Stats test 2d failed.")
allPassed = false
}
if (stats.minCodePoint != 0) {
game.splash("Stats test 2e failed.")
allPassed = false
}
if (stats.maxCodePoint != 0) {
game.splash("Stats test 2f failed.")
allPassed = false
}
if (stats.surrogates != 0) {
game.splash("Stats test 2g failed.")
allPassed = false
}

// Stats for singleton length 1 string.
test = new TernaryStringSet()
test.add("B")
stats = test.stats
if (stats.size != 1) {
game.splash("Stats test 3a failed.")
allPassed = false
}
if (stats.nodes != 1) {
game.splash("Stats test 3b failed.")
allPassed = false
}
if (stats.depth != 1) {
game.splash("Stats test 3c failed.")
allPassed = false
}
if (stats.breadth.length != 1) {
game.splash("Stats test 3d failed.")
allPassed = false
}
if (stats.minCodePoint != 66) {
game.splash("Stats test 3e failed.")
allPassed = false
}
if (stats.maxCodePoint != 66) {
game.splash("Stats test 3f failed.")
allPassed = false
}
if (stats.surrogates != 0) {
game.splash("Stats test 3g failed.")
allPassed = false
}

// Stats for tree with single left child.
test = new TernaryStringSet()
test.add("B")
test.add("A")
stats = test.stats
if (stats.size != 2) {
game.splash("Stats test 4a failed.")
allPassed = false
}
if (stats.nodes != 2) {
game.splash("Stats test 4b failed.")
allPassed = false
}
if (stats.depth != 2) {
game.splash("Stats test 4c failed.")
allPassed = false
}
if (stats.breadth.length != 2) {
game.splash("Stats test 4d failed.")
allPassed = false
}
if (stats.minCodePoint != 65) {
game.splash("Stats test 4e failed.")
allPassed = false
}
if (stats.maxCodePoint != 66) {
game.splash("Stats test 4f failed.")
allPassed = false
}
if (stats.surrogates != 0) {
game.splash("Stats test 4g failed.")
allPassed = false
}

// Stats for tree with both children.
test = new TernaryStringSet()
test.add("B")
test.add("A")
test.add("C")
stats = test.stats
if (stats.size != 3) {
game.splash("Stats test 5a failed.")
allPassed = false
}
if (stats.nodes != 3) {
game.splash("Stats test 5b failed.")
allPassed = false
}
if (stats.depth != 2) {
game.splash("Stats test 5c failed.")
allPassed = false
}
if (stats.breadth.length != 2) {
game.splash("Stats test 5d failed.")
allPassed = false
}
if (stats.minCodePoint != 65) {
game.splash("Stats test 5e failed.")
allPassed = false
}
if (stats.maxCodePoint != 67) {
game.splash("Stats test 5f failed.")
allPassed = false
}
if (stats.surrogates != 0) {
game.splash("Stats test 5g failed.")
allPassed = false
}

// Stats for three-level tree.
test = new TernaryStringSet()
test.add("B")
test.add("A")
test.add("C")
test.add("D")
stats = test.stats
if (stats.size != 4) {
game.splash("Stats test 6a failed.")
allPassed = false
}
if (stats.nodes != 4) {
game.splash("Stats test 6b failed.")
allPassed = false
}
if (stats.depth != 3) {
game.splash("Stats test 6c failed.")
allPassed = false
}
if (stats.breadth.length != 3) {
game.splash("Stats test 6d failed.")
allPassed = false
}
if (stats.minCodePoint != 65) {
game.splash("Stats test 6e failed.")
allPassed = false
}
if (stats.maxCodePoint != 68) {
game.splash("Stats test 6f failed.")
allPassed = false
}
if (stats.surrogates != 0) {
game.splash("Stats test 6g failed.")
allPassed = false
}

return allPassed
}
}

0 comments on commit d8fae79

Please sign in to comment.