Libraryless. Click here for Pure Java version (6400L/36K).
1 | // uses Int as values by default |
2 | asclass TestUnorderedSet { |
3 | new HashSet a; |
4 | Set b; |
5 | settable Int randomSeed; |
6 | |
7 | abstract Set makeSet(); |
8 | |
9 | int n = 1000, valueRange = 100; |
10 | bool remove = true; |
11 | |
12 | O makeEntry() { ret random(valueRange); } |
13 | O randomNonContainedEntry() { ret random(valueRange+1, valueRange*2); } |
14 | |
15 | S moreInfo(Set b) { ret ""; } |
16 | |
17 | void printStats { |
18 | print(joinNemptiesWithSlash(n2(b), moreInfo(b)) + " - " + takeFirst(10, b.iterator()); |
19 | print(/*"Size HashSet: " + n2(deepObjectSize(a))*/ |
20 | "Size " + shortClassName(b) + ": " + n2(deepObjectSize(b))); |
21 | } |
22 | |
23 | run { |
24 | temp tempSetRandomSeedUnlessNull(randomSeed); |
25 | |
26 | b = makeSet(); |
27 | printStats(); |
28 | repeat n { |
29 | var o = makeEntry(); |
30 | bool change = addToTwoCollections(a, b, o); |
31 | print((change ? "Added " : "Already contained ") + o); |
32 | if (remove) { |
33 | o = makeEntry(); |
34 | change = removeFromTwoCollections(a, b, o); |
35 | print((change ? "Removed " : "Didn't contain ") + o); |
36 | } |
37 | assertSetsEqual(a, b); |
38 | repeat 5 { assertFalse(b.contains(randomNonContainedEntry())); } |
39 | printStats(); |
40 | } |
41 | } |
42 | } |
Began life as a copy of #1032013
download show line numbers debug dex old transpilations
Travelled to 4 computer(s): bhatertpkbcr, ekrmjmnbrukm, mowyntqkapby, mqqgnosmbjvj
No comments. add comment
Snippet ID: | #1033827 |
Snippet name: | TestUnorderedSet |
Eternal ID of this version: | #1033827/18 |
Text MD5: | 0006dda4e334f71e1ecf1448d4493abf |
Transpilation MD5: | e37b658be03b117186480a068a583ab2 |
Author: | stefan |
Category: | javax |
Type: | JavaX fragment (include) |
Public (visible to everyone): | Yes |
Archived (hidden from active list): | No |
Created/modified: | 2022-03-14 19:51:37 |
Source code size: | 1186 bytes / 42 lines |
Pitched / IR pitched: | No / No |
Views / Downloads: | 149 / 323 |
Version history: | 17 change(s) |
Referenced in: | [show references] |