-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
stdlib: use
Identity
in HashMap
and HashSet
and add tests for s…
…pecial float values
- Loading branch information
Showing
10 changed files
with
117 additions
and
33 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
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,20 @@ | ||
fun main(): Unit { | ||
float64(); | ||
float32(); | ||
} | ||
|
||
fun float64(): Unit { | ||
let map = std::HashMap[Float64, String]::new((Float64::notANumber(), "a")); | ||
|
||
assert(map.size() == 1i64); | ||
assert(map.contains(Float64::notANumber())); | ||
assert(map.get(Float64::notANumber()).getOrPanic() == "a"); | ||
} | ||
|
||
fun float32(): Unit { | ||
let map = std::HashMap[Float32, String]::new((Float32::notANumber(), "a")); | ||
|
||
assert(map.size() == 1i64); | ||
assert(map.contains(Float32::notANumber())); | ||
assert(map.get(Float32::notANumber()).getOrPanic() == "a"); | ||
} |
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,24 @@ | ||
fun main(): Unit { | ||
float64(); | ||
float32(); | ||
} | ||
|
||
fun float64(): Unit { | ||
let map = std::HashMap[Float64, String]::new((0.0, "a")); | ||
|
||
assert(map.size() == 1i64); | ||
assert(map.contains(0.0)); | ||
assert(map.get(0.0).getOrPanic() == "a"); | ||
assert(map.contains(-0.0)); // FIXME: this only works by coincidence, because the hash function sucks | ||
assert(map.get(-0.0).getOrPanic() == "a"); // FIXME: this only works by coincidence, because the hash function sucks | ||
} | ||
|
||
fun float32(): Unit { | ||
let map = std::HashMap[Float32, String]::new((0.0f32, "a")); | ||
|
||
assert(map.size() == 1i64); | ||
assert(map.contains(0.0f32)); | ||
assert(map.get(0.0f32).getOrPanic() == "a"); | ||
assert(map.contains(-0.0f32).not()); // FIXME: should be true instead | ||
// assert(map.get(-0.0f32).getOrPanic() == "a"); // FIXME: should be true instead | ||
} |
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,16 @@ | ||
fun main(): Unit { | ||
let map = std::HashMap[Int32, String]::new((1i32, "a"), (2i32, "b"), (3i32, "c"), (4i32, "d")); | ||
|
||
assert(map.size() == 4i64); | ||
|
||
assert(map.contains(1i32)); | ||
assert(map.contains(2i32)); | ||
assert(map.contains(3i32)); | ||
assert(map.contains(4i32)); | ||
assert(map.contains(0i32).not()); | ||
|
||
assert(map.get(1i32).getOrPanic() == "a"); | ||
assert(map.get(2i32).getOrPanic() == "b"); | ||
assert(map.get(3i32).getOrPanic() == "c"); | ||
assert(map.get(4i32).getOrPanic() == "d"); | ||
} |
File renamed without changes.
This file was deleted.
Oops, something went wrong.
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,18 @@ | ||
fun main(): Unit { | ||
float64(); | ||
float32(); | ||
} | ||
|
||
fun float64(): Unit { | ||
let set = std::HashSet[Float64]::new(Float64::notANumber()); | ||
|
||
assert(set.size() == 1i64); | ||
assert(set.contains(Float64::notANumber())); | ||
} | ||
|
||
fun float32(): Unit { | ||
let set = std::HashSet[Float32]::new(Float32::notANumber()); | ||
|
||
assert(set.size() == 1i64); | ||
assert(set.contains(Float32::notANumber())); | ||
} |
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,20 @@ | ||
fun main(): Unit { | ||
float64(); | ||
float32(); | ||
} | ||
|
||
fun float64(): Unit { | ||
let set = std::HashSet[Float64]::new(0.0); | ||
|
||
assert(set.size() == 1i64); | ||
assert(set.contains(0.0)); | ||
assert(set.contains(-0.0)); // FIXME: this only works by coincidence, because the hash function sucks | ||
} | ||
|
||
fun float32(): Unit { | ||
let set = std::HashSet[Float32]::new(0.0f32); | ||
|
||
assert(set.size() == 1i64); | ||
assert(set.contains(0.0f32)); | ||
assert(set.contains(-0.0f32).not()); // FIXME: should be true instead | ||
} |
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,9 @@ | ||
fun main(): Unit { | ||
let set = std::HashSet[Int32]::new(1i32, 10'000i32, 7i32); | ||
|
||
assert(set.size() == 3i64); | ||
assert(set.contains(1i32)); | ||
assert(set.contains(10'000i32)); | ||
assert(set.contains(7i32)); | ||
assert(set.contains(0i32).not()); | ||
} |
This file was deleted.
Oops, something went wrong.