|
| 1 | +// Copyright 2025 International Digital Economy Academy |
| 2 | +// |
| 3 | +// Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | +// you may not use this file except in compliance with the License. |
| 5 | +// You may obtain a copy of the License at |
| 6 | +// |
| 7 | +// http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | +// |
| 9 | +// Unless required by applicable law or agreed to in writing, software |
| 10 | +// distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | +// See the License for the specific language governing permissions and |
| 13 | +// limitations under the License. |
| 14 | + |
| 15 | +///| |
| 16 | +let seed = 0x533D |
| 17 | + |
| 18 | +///| |
| 19 | +fn h() -> Hasher { |
| 20 | + Hasher::new(seed~) |
| 21 | +} |
| 22 | + |
| 23 | +///| |
| 24 | +test "hash_combine for 2-tuple" { |
| 25 | + assert_eq!( |
| 26 | + h()..combine(1)..combine("hello").finalize(), |
| 27 | + h()..combine((1, "hello")).finalize(), |
| 28 | + ) |
| 29 | +} |
| 30 | + |
| 31 | +///| |
| 32 | +test "hash_combine for 3-tuple" { |
| 33 | + assert_eq!( |
| 34 | + h()..combine(1)..combine("hello")..combine(3.14).finalize(), |
| 35 | + h()..combine((1, "hello", 3.14)).finalize(), |
| 36 | + ) |
| 37 | +} |
| 38 | + |
| 39 | +///| |
| 40 | +test "hash_combine for 4-tuple" { |
| 41 | + assert_eq!( |
| 42 | + h()..combine(1)..combine("hello")..combine(3.14)..combine(15).finalize(), |
| 43 | + h()..combine((1, "hello", 3.14, 15)).finalize(), |
| 44 | + ) |
| 45 | +} |
| 46 | + |
| 47 | +///| |
| 48 | +test "hash_combine for 5-tuple" { |
| 49 | + assert_eq!( |
| 50 | + h() |
| 51 | + ..combine(1) |
| 52 | + ..combine("hello") |
| 53 | + ..combine(3.14) |
| 54 | + ..combine(15) |
| 55 | + ..combine('a') |
| 56 | + .finalize(), |
| 57 | + h()..combine((1, "hello", 3.14, 15, 'a')).finalize(), |
| 58 | + ) |
| 59 | +} |
| 60 | + |
| 61 | +///| |
| 62 | +test "hash_combine for 6-tuple" { |
| 63 | + assert_eq!( |
| 64 | + h() |
| 65 | + ..combine(1) |
| 66 | + ..combine("hello") |
| 67 | + ..combine(3.14) |
| 68 | + ..combine(15) |
| 69 | + ..combine('a') |
| 70 | + ..combine(0x12345678UL) |
| 71 | + .finalize(), |
| 72 | + h()..combine((1, "hello", 3.14, 15, 'a', 0x12345678UL)).finalize(), |
| 73 | + ) |
| 74 | +} |
| 75 | + |
| 76 | +///| |
| 77 | +test "hash_combine for 7-tuple" { |
| 78 | + assert_eq!( |
| 79 | + h() |
| 80 | + ..combine(1) |
| 81 | + ..combine("hello") |
| 82 | + ..combine(3.14) |
| 83 | + ..combine(15) |
| 84 | + ..combine('a') |
| 85 | + ..combine(0x12345678UL) |
| 86 | + ..combine(b's') |
| 87 | + .finalize(), |
| 88 | + h()..combine((1, "hello", 3.14, 15, 'a', 0x12345678UL, b's')).finalize(), |
| 89 | + ) |
| 90 | +} |
0 commit comments