-
Notifications
You must be signed in to change notification settings - Fork 92
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Missing test coverage for builtin Eq/Hash/Show impl of tuples #1186
Comments
It seems that Eq tests already exist in tuple/tuple_test.mbt, while Compare/Hash tests are still missing. |
According to the current implementation, it seems that the hash value of |
I tested the hash implementation for tuple in Rust and got some weird results. use std::hash::{DefaultHasher, Hash, Hasher};
fn calculate_hash<T: Hash>(t: &T) -> u64 {
let mut s = DefaultHasher::new();
t.hash(&mut s);
s.finish()
}
fn main() {
let tuple1 = (1, 2, 3);
let tuple2 = (1, (2, 3));
let tuple3 = (1 as u32, 2, 3);
let tuple4 = (1 as i64, 2, 3);
println!(
"{} {} {} {}",
calculate_hash(&tuple1), // 646939227381880718
calculate_hash(&tuple2), // 646939227381880718
calculate_hash(&tuple3), // 646939227381880718
calculate_hash(&tuple4), // 4417724211370468105
);
assert_eq!(calculate_hash(&tuple1), calculate_hash(&tuple2));
assert_eq!(calculate_hash(&tuple1), calculate_hash(&tuple3));
assert_ne!(calculate_hash(&tuple1), calculate_hash(&tuple4));
} Moonbit's current implementation is consistent with Rust, except that multiple builtin types have not implemented Hash trait yet (eg. Int64, Array[Int] #938 ). test "hash" {
let tuple1 = (1, 2, 3)
let tuple2 = (1, (2, 3))
let tuple3 = (1U, 2, 3)
// let tuple4 = (1L, 2, 3)
inspect!(tuple1.hash() == tuple1.hash(), content="true")
inspect!(tuple1.hash() == tuple2.hash(), content="true")
inspect!(tuple1.hash() == tuple3.hash(), content="true")
// inspect!(tuple1.hash() == tuple4.hash(), content="false") // Type Int64 does not implement trait Hash
} |
Show tests seem to exist too. So I just added Compare/Hash tests. |
No description provided.
The text was updated successfully, but these errors were encountered: