render_example_test.gno
1.40 Kb · 45 lines
1package multisetdemo
2
3// ExampleRender pins the realm's Render output as a testable example.
4func ExampleRender() {
5 print(Render(""))
6 // Output:
7 // # Multiset
8 //
9 // A bag that counts duplicates, demoing the [`p/moul/x/daily/multiset`](/p/nym-moultest123/x/daily/multiset/v0) library.
10 //
11 // ## Word frequencies
12 //
13 // > the quick brown fox jumps over the lazy dog the fox barks and the dog barks
14 //
15 // `16` words, `10` distinct.
16 //
17 // ## `MostCommon(5)`
18 //
19 // | rank | word | count |
20 // |---|---|---|
21 // | 1 | `the` | 4 |
22 // | 2 | `barks` | 2 |
23 // | 3 | `dog` | 2 |
24 // | 4 | `fox` | 2 |
25 // | 5 | `and` | 1 |
26 //
27 // Note the ties. `barks`, `dog` and `fox` all occur twice and are ranked **alphabetically** — the order is count descending, then element ascending. That second key is not decoration: without it the ranking would fall back on map iteration order, which gno leaves unspecified, and two nodes could render different tables.
28 //
29 // ## Algebra
30 //
31 // With `A = {x:3, y:1}` and `B = {x:2, z:1}`:
32 //
33 // | op | meaning | result |
34 // |---|---|---|
35 // | `Union` | max of each count | `{x:3, y:1, z:1}` |
36 // | `Intersect` | min, common only | `{x:2}` |
37 // | `Sum` | counts added | `{x:5, y:1, z:1}` |
38 //
39 // ## Removal
40 //
41 // Starting from `{a:3}`:
42 //
43 // - after `Remove("a")` → `{a:2}`
44 // - after `RemoveN("a", 100)` → `{}` — over-removing clears the element instead of going negative
45}