-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
f5abe3d
commit 6c97f8b
Showing
4 changed files
with
212 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,154 @@ | ||
namespace DeleteTests { | ||
export function run(): boolean { | ||
let test: TernaryStringSet | ||
let allPassed: boolean = true | ||
|
||
// delete() empty string. | ||
test = new TernaryStringSet() | ||
test.add("") | ||
test.add("horse") | ||
if (test.size != 2) { | ||
game.splash("Delete test 1a failed.") | ||
allPassed = false | ||
} | ||
if (!test.has("")) { | ||
game.splash("Delete test 1b failed.") | ||
allPassed = false | ||
} | ||
test.delete("") | ||
if (test.size != 1) { | ||
game.splash("Delete test 1c failed.") | ||
allPassed = false | ||
} | ||
if (test.has("")) { | ||
game.splash("Delete test 1d failed.") | ||
allPassed = false | ||
} | ||
|
||
// delete() non-member. | ||
test = new TernaryStringSet() | ||
if (test.size != 0) { | ||
game.splash("Delete test 2a failed.") | ||
allPassed = false | ||
} | ||
test.add("dog") | ||
if (test.size != 1) { | ||
game.splash("Delete test 2b failed.") | ||
allPassed = false | ||
} | ||
if (test.has("cat")) { | ||
game.splash("Delete test 2c failed.") | ||
allPassed = false | ||
} | ||
if (test.delete("cat")) { | ||
game.splash("Delete test 2d failed.") | ||
allPassed = false | ||
} | ||
if (test.size != 1) { | ||
game.splash("Delete test 2e failed.") | ||
allPassed = false | ||
} | ||
|
||
// delete() member | ||
test = new TernaryStringSet() | ||
if (test.size != 0) { | ||
game.splash("Delete test 3a failed.") | ||
allPassed = false | ||
} | ||
test.add("dog") | ||
if (test.size != 1) { | ||
game.splash("Delete test 3b failed.") | ||
allPassed = false | ||
} | ||
if (!test.has("dog")) { | ||
game.splash("Delete test 3c failed.") | ||
allPassed = false | ||
} | ||
if (!test.delete("dog")) { | ||
game.splash("Delete test 3d failed.") | ||
allPassed = false | ||
} | ||
if (test.size != 0) { | ||
game.splash("Delete test 3e failed.") | ||
allPassed = false | ||
} | ||
|
||
// delete() returns whether element was present. | ||
test = new TernaryStringSet() | ||
test.addAll(ShortEnglishList.words) | ||
ShortEnglishList.words.forEach((s: string) => { | ||
if (!test.delete(s)) { | ||
game.splash(`Delete test 4a failed for word ${s}.`) | ||
allPassed = false | ||
} | ||
}) | ||
if (test.size != 0) { | ||
game.splash("Delete test 4b failed.") | ||
allPassed = false | ||
} | ||
if (test.delete("")) { | ||
game.splash("Delete test 4c failed.") | ||
allPassed = false | ||
} | ||
test.add("") | ||
if (test.delete("cat")) { | ||
game.splash("Delete test 4d failed.") | ||
allPassed = false | ||
} | ||
if (!test.delete("")) { | ||
game.splash("Delete test 4e failed.") | ||
allPassed = false | ||
} | ||
if (test.delete("cat")) { | ||
game.splash("Delete test 4f failed.") | ||
allPassed = false | ||
} | ||
|
||
// delete() multiple. | ||
test = new TernaryStringSet() | ||
test.addAll(ShortEnglishList.words) | ||
let size: number = test.size | ||
let count: number = 0 | ||
let randomOrder: string[] = getShuffledWords() | ||
for (let w of randomOrder) { | ||
if (test.size != size) { | ||
game.splash(`Delete test 5a failed for word ${w} count ${count}.`) | ||
allPassed = false | ||
} | ||
size-- | ||
if (!test.has(w)) { | ||
game.splash(`Delete test 5b failed for word ${w} count ${count}.`) | ||
allPassed = false | ||
} | ||
if (!test.delete(w)) { | ||
game.splash(`Delete test 5c failed for word ${w} count ${count}.`) | ||
allPassed = false | ||
} | ||
if (test.has(w)) { | ||
game.splash(`Delete test 5d failed for word ${w} count ${count}.`) | ||
allPassed = false | ||
} | ||
count++ | ||
} | ||
if (test.size != 0) { | ||
game.splash("Delete test 5e failed.") | ||
allPassed = false | ||
} | ||
|
||
return allPassed | ||
} | ||
|
||
function getShuffledWords(): string[] { | ||
let shuffled: string[] = ShortEnglishList.words.slice() | ||
let len: number = shuffled.length | ||
for (let i: number = 0; i < len; i++) { | ||
let swapIndex: number = randint(0, len - 1) | ||
if (i != swapIndex) { | ||
let temp: string = shuffled[i] | ||
shuffled[i] = shuffled[swapIndex] | ||
shuffled[swapIndex] = temp | ||
} | ||
} | ||
return shuffled | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
namespace SizeTests { | ||
export function run(): boolean { | ||
let test: TernaryStringSet | ||
let allPassed: boolean = true | ||
|
||
// size() not double counted. | ||
test = new TernaryStringSet() | ||
if (test.size != 0) { | ||
game.splash("Size test 1a failed.") | ||
allPassed = false | ||
} | ||
test.add("peach") | ||
if (test.size != 1) { | ||
game.splash("Size test 1b failed.") | ||
allPassed | ||
} | ||
test.add("peach") | ||
if (test.size != 1) { | ||
game.splash("Size test 1c failed.") | ||
allPassed | ||
} | ||
|
||
// size() not double deleted. | ||
test = new TernaryStringSet() | ||
if (test.size != 0) { | ||
game.splash("Size test 2a failed.") | ||
allPassed = false | ||
} | ||
test.add("peach") | ||
if (test.size != 1) { | ||
game.splash("Size test 2b failed.") | ||
allPassed | ||
} | ||
test.delete("peach") | ||
if (test.size != 0) { | ||
game.splash("Size test 2c failed.") | ||
allPassed = false | ||
} | ||
test.delete("peach") | ||
if (test.size != 0) { | ||
game.splash("Size test 2d failed.") | ||
allPassed = false | ||
} | ||
return allPassed | ||
} | ||
} |