forked from topology-foundation/ts-topology
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
08ace2b
commit 007ae91
Showing
8 changed files
with
1,432 additions
and
1,478 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
import { describe, test, expect, beforeEach, afterEach } from "vitest"; | ||
import { GCounter } from "../src/builtins/GCounter"; | ||
|
||
describe("G-Counter Tests", () => { | ||
|
||
let set1: GCounter; | ||
let set2: GCounter; | ||
|
||
beforeEach(() => { | ||
set1 = new GCounter({ "node1": 5, "node2": 10}); | ||
set2 = new GCounter({ "node1": 5, "node2": 10}); | ||
}); | ||
|
||
test("Test Initial Values", () => { | ||
expect(set1.value()).toBe(15); | ||
expect(set2.value()).toBe(15); | ||
}); | ||
|
||
test("Test Increment", () => { | ||
|
||
set1.increment("node1", 10); | ||
set1.increment("node2", 5); | ||
|
||
expect(set1.value()).toBe(30); | ||
}); | ||
|
||
test("Test Compare", () => { | ||
|
||
expect(set1.compare(set2)).toBe(true); | ||
|
||
set2.increment("node1", 5); | ||
|
||
expect(set1.compare(set2)).toBe(false); | ||
|
||
let set3 = new GCounter({ "node1": 5, "node2": 10, "node3": 15 }); | ||
|
||
expect(set1.compare(set3)).toBe(false); | ||
}); | ||
|
||
test("Test Merge", () => { | ||
|
||
const counter1 = new GCounter({ "node1": 5 }); | ||
const counter2 = new GCounter({ "node2": 10 }); | ||
|
||
counter1.merge(counter2); | ||
|
||
expect(counter1.counts).toEqual({ "node1": 5, "node2": 10 }); | ||
expect(counter1.value()).toBe(15); | ||
|
||
set1.increment("node1", 5); | ||
set2.increment("node2", 10); | ||
expect(set1.value()).toBe(35); | ||
expect(set2.value()).toBe(40); | ||
set1.merge(set2); | ||
expect(set1.value()).toBe(45); | ||
expect(set1.counts[0]).toBe(10); | ||
expect(set1.counts[1]).toBe(20); | ||
expect(set1.counts[2]).toBe(15); | ||
|
||
set2.merge(set1); | ||
expect(set2.value()).toBe(45); | ||
expect(set2.counts[0]).toBe(10); | ||
expect(set2.counts[1]).toBe(20); | ||
expect(set2.counts[2]).toBe(15); | ||
|
||
expect(set2.compare(set1)).toBe(true); | ||
}); | ||
|
||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
import { describe, test, expect, beforeEach, afterEach } from "vitest"; | ||
import { GSet } from "../src/builtins/GSet"; | ||
|
||
describe("G-Set Tests", () => { | ||
|
||
let set1: GSet<string>; | ||
let set2: GSet<string>; | ||
|
||
beforeEach(() => { | ||
set1 = new GSet<string>(new Set<string>(["walter", "jesse", "mike"])); | ||
set2 = new GSet<string>(new Set<string>(["walter", "jesse", "mike"])); | ||
}); | ||
|
||
test("Test Add", () => { | ||
set1.add("gustavo"); | ||
set2.add("gustavo"); | ||
|
||
expect(set1.lookup("gustavo")).toBe(true); | ||
expect(set2.lookup("gustavo")).toBe(true); | ||
}); | ||
|
||
test("Test Compare", () => { | ||
expect(set1.compare(set2)).toBe(true); | ||
|
||
set1.add("gustavo"); | ||
|
||
expect(set1.compare(set2)).toBe(false); | ||
|
||
set2.add("gustavo"); | ||
|
||
expect(set1.compare(set2)).toBe(true); | ||
}); | ||
|
||
test("Test Merge", () => { | ||
set1.add("gustavo"); | ||
set2.add("lalo"); | ||
|
||
expect(set1.compare(set2)).toBe(false); | ||
|
||
set1.merge(set2); | ||
set2.merge(set1); | ||
|
||
expect(set1.compare(set2)).toBe(true); | ||
|
||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,106 @@ | ||
import { describe, test, expect, beforeEach } from "vitest"; | ||
import { LWWElementSet, Bias } from "../src/builtins/LWWElementSet"; | ||
|
||
describe("LWW-Element-Set Tests", () => { | ||
|
||
const testValues = ["walter", "jesse", "mike"]; | ||
|
||
let set1: LWWElementSet<string>; | ||
let set2: LWWElementSet<string>; | ||
let set3: LWWElementSet<string>; | ||
|
||
beforeEach(() => { | ||
set1 = new LWWElementSet<string>(new Map(), new Map(), Bias.ADD); | ||
set2 = new LWWElementSet<string>(new Map(), new Map(), Bias.ADD); | ||
set3 = new LWWElementSet<string>(new Map(), new Map(), Bias.REMOVE); | ||
|
||
testValues.forEach((value) => { | ||
set1.add(value); | ||
set2.add(value); | ||
set3.add(value); | ||
}); | ||
}); | ||
|
||
test("Test Add Elements", () => { | ||
|
||
expect(set1.lookup("gustavo")).toBe(false); | ||
|
||
set1.add("gustavo"); | ||
|
||
expect(set1.lookup("gustavo")).toBe(true); | ||
|
||
}); | ||
|
||
test("Test Remove Elements", () => { | ||
|
||
expect(set1.lookup("mike")).toBe(true); | ||
|
||
set1.remove("mike"); | ||
|
||
expect(set1.lookup("mike")).toBe(false); | ||
|
||
}); | ||
|
||
test("Test Compare Sets", () => { | ||
|
||
expect(set1.compare(set2)).toBe(true); | ||
expect(set1.compare(set3)).toBe(true); | ||
expect(set3.compare(set2)).toBe(true); | ||
|
||
set1.remove("jesse"); | ||
|
||
expect(set1.compare(set2)).toBe(false); | ||
expect(set1.compare(set3)).toBe(false); | ||
expect(set3.compare(set2)).toBe(true); | ||
|
||
}); | ||
|
||
describe("Test Merge Elements" , () => { | ||
|
||
test("Merge Sets", () => { | ||
|
||
// Adding different names to each set | ||
set1.add("gustavo"); | ||
set2.add("saul"); | ||
|
||
expect(set1.compare(set2)).toBe(false); | ||
|
||
set1.merge(set2); | ||
set2.merge(set1); | ||
|
||
expect(set1.compare(set2)).toBe(true); | ||
|
||
}); | ||
|
||
test("Same Element, different Timestamps", () => { | ||
|
||
const timestamp = Date.now(); | ||
set1.getAdds().set("gustavo", timestamp); | ||
set2.getAdds().set("gustavo", timestamp + 5); | ||
|
||
expect(set1.getAdds().get("gustavo")).toBe(timestamp); | ||
|
||
set1.merge(set2); | ||
set2.merge(set1); | ||
|
||
expect(set1.getAdds().get("gustavo")).toBe(timestamp + 5); | ||
expect(set2.getAdds().get("gustavo")).toBe(timestamp + 5); | ||
|
||
}); | ||
|
||
test("Merge Removal Timestamps", () => { | ||
|
||
const timestamp = Date.now(); | ||
|
||
set1.getAdds().set("gustavo", timestamp); | ||
set2.getRemoves().set("gustavo", timestamp + 5); | ||
|
||
set1.merge(set2); | ||
|
||
|
||
expect(set1.lookup("gustavo")).toBe(false); | ||
expect(set1.getRemoves().get("gustavo")).toBe(timestamp + 5); | ||
|
||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
import { describe, test, expect, beforeEach, afterEach } from "vitest"; | ||
import { PNCounter } from "../src/builtins/PNCounter"; | ||
import { GCounter } from "../src/builtins/GCounter"; | ||
|
||
describe("PN-Counter Tests", () => { | ||
|
||
let set1: PNCounter; | ||
let set2: PNCounter; | ||
|
||
beforeEach(() => { | ||
set1 = new PNCounter(new GCounter({ 0: 5, 1: 10, 2: 15 }), new GCounter({ 0: 3, 1: 4, 2: 3 })); | ||
set2 = new PNCounter(new GCounter({ 0: 5, 1: 10, 2: 15 }), new GCounter({ 0: 3, 1: 4, 2: 3 })); | ||
}); | ||
|
||
test("Test Initial Value", () => { | ||
expect(set1.value()).toBe(20); | ||
expect(set2.value()).toBe(20); | ||
}); | ||
|
||
test("Test Increment", () => { | ||
set1.increment(0,10); | ||
set2.increment(0,20); | ||
expect(set1.value()).toBe(30); | ||
expect(set2.value()).toBe(40); | ||
}); | ||
|
||
test("Test Decrement", () => { | ||
set1.decrement(0,10); | ||
set2.decrement(0,20); | ||
expect(set1.value()).toBe(10); | ||
expect(set2.value()).toBe(0); | ||
}); | ||
|
||
test("Test Compare", () => { | ||
expect(set1.compare(set2)).toBe(true); | ||
|
||
set1.decrement(0,10); | ||
|
||
expect(set1.compare(set2)).toBe(false); | ||
|
||
set2.decrement(0,10); | ||
|
||
expect(set1.compare(set2)).toBe(true); | ||
}); | ||
|
||
test("Test Merge", () => { | ||
set1.increment(0,10); | ||
set2.decrement(1,5); | ||
|
||
expect(set1.compare(set2)).toBe(false); | ||
expect(set2.compare(set1)).toBe(false); | ||
|
||
set1.merge(set2); | ||
set2.merge(set1); | ||
|
||
expect(set1.compare(set2)).toBe(true); | ||
expect(set2.compare(set1)).toBe(true); | ||
}); | ||
|
||
}); |
Oops, something went wrong.