|
| 1 | +//go:build go1.21 |
| 2 | +// +build go1.21 |
| 3 | + |
| 4 | +/* |
| 5 | +Open Source Initiative OSI - The MIT License (MIT):Licensing |
| 6 | +
|
| 7 | +The MIT License (MIT) |
| 8 | +Copyright (c) 2013 - 2022 Ralph Caraveo ([email protected]) |
| 9 | +
|
| 10 | +Permission is hereby granted, free of charge, to any person obtaining a copy of |
| 11 | +this software and associated documentation files (the "Software"), to deal in |
| 12 | +the Software without restriction, including without limitation the rights to |
| 13 | +use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies |
| 14 | +of the Software, and to permit persons to whom the Software is furnished to do |
| 15 | +so, subject to the following conditions: |
| 16 | +
|
| 17 | +The above copyright notice and this permission notice shall be included in all |
| 18 | +copies or substantial portions of the Software. |
| 19 | +
|
| 20 | +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 21 | +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 22 | +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
| 23 | +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
| 24 | +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
| 25 | +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE |
| 26 | +SOFTWARE. |
| 27 | +*/ |
| 28 | + |
| 29 | +package mapset |
| 30 | + |
| 31 | +import ( |
| 32 | + "testing" |
| 33 | +) |
| 34 | + |
| 35 | +func Test_Sorted(t *testing.T) { |
| 36 | + test := func(t *testing.T, ctor func(vals ...string) Set[string]) { |
| 37 | + set := ctor("apple", "banana", "pear") |
| 38 | + sorted := Sorted(set) |
| 39 | + |
| 40 | + if len(sorted) != set.Cardinality() { |
| 41 | + t.Errorf("Length of slice is not the same as the set. Expected: %d. Actual: %d", set.Cardinality(), len(sorted)) |
| 42 | + } |
| 43 | + |
| 44 | + if sorted[0] != "apple" { |
| 45 | + t.Errorf("Element 0 was not equal to apple: %s", sorted[0]) |
| 46 | + } |
| 47 | + if sorted[1] != "banana" { |
| 48 | + t.Errorf("Element 1 was not equal to banana: %s", sorted[1]) |
| 49 | + } |
| 50 | + if sorted[2] != "pear" { |
| 51 | + t.Errorf("Element 2 was not equal to pear: %s", sorted[2]) |
| 52 | + } |
| 53 | + } |
| 54 | + |
| 55 | + t.Run("Safe", func(t *testing.T) { |
| 56 | + test(t, NewSet[string]) |
| 57 | + }) |
| 58 | + t.Run("Unsafe", func(t *testing.T) { |
| 59 | + test(t, NewThreadUnsafeSet[string]) |
| 60 | + }) |
| 61 | +} |
0 commit comments