Not logged in.  Login/Logout/Register | List snippets | | Create snippet | Upload image | Upload data

42
LINES

< > BotCompany Repo | #1033827 // TestUnorderedSet

JavaX fragment (include) [tags: use-pretranspiled]

Libraryless. Click here for Pure Java version (6400L/36K).

// uses Int as values by default
asclass TestUnorderedSet {
  new HashSet a;
  Set b;
  settable Int randomSeed;
  
  abstract Set makeSet();

  int n = 1000, valueRange = 100;
  bool remove = true;
  
  O makeEntry() { ret random(valueRange); }
  O randomNonContainedEntry() { ret random(valueRange+1, valueRange*2); }
  
  S moreInfo(Set b) { ret ""; }
  
  void printStats {
    print(joinNemptiesWithSlash(n2(b), moreInfo(b)) + " - " + takeFirst(10, b.iterator());
    print(/*"Size HashSet: " + n2(deepObjectSize(a))*/
      "Size " + shortClassName(b) + ": " + n2(deepObjectSize(b)));
  }
  
  run {
    temp tempSetRandomSeedUnlessNull(randomSeed);

    b = makeSet();
    printStats();
    repeat n {
      var o = makeEntry();
      bool change = addToTwoCollections(a, b, o);
      print((change ? "Added " : "Already contained ") + o);
      if (remove) {
        o = makeEntry();
        change = removeFromTwoCollections(a, b, o);
        print((change ? "Removed " : "Didn't contain ") + o);
      }
      assertSetsEqual(a, b);
      repeat 5 { assertFalse(b.contains(randomNonContainedEntry())); }
      printStats();
    }
  }
}

Author comment

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: 150 / 325
Version history: 17 change(s)
Referenced in: #1034167 - Standard Classes + Interfaces (LIVE, continuation of #1003674)