-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathtest.mjs
More file actions
executable file
·39 lines (38 loc) · 1.26 KB
/
test.mjs
File metadata and controls
executable file
·39 lines (38 loc) · 1.26 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
import Logic from './index.mjs'
import assert from 'assert'
import {describe, it} from 'node:test'
describe("Logic-solver mjs",()=>{
it("should find all solutions to the example problem",async ()=>{
let solver = new Logic.Solver()
await solver.initialize()
solver.require(Logic.atMostOne("Alice", "Bob"));
solver.require(Logic.or("Bob", "Charlie"));
var solutions = [];
var curSol;
while ((curSol = solver.solve())) {
solutions.push(curSol.getTrueVars());
solver.forbid(curSol.getFormula());
}
let expected = [
[ 'Bob' ],
[ 'Bob', 'Charlie' ],
[ 'Charlie' ],
[ 'Alice', 'Charlie' ]
].sort()
solutions.sort()
assert.deepEqual(solutions, expected)
})
it("should be able to use .product and .subtract",async ()=>{
let solver = new Logic.Solver()
await solver.initialize()
let numA = Logic.variableBits("a",6)
let numB = Logic.variableBits("b",6)
solver.require(Logic.equalBits(Logic.product(numA,numB),Logic.constantBits(48)))
solver.require(Logic.equalBits(Logic.subtract(numA,numB),Logic.constantBits(2)))
let solution = solver.solve()
let valA = solution.evaluate(numA)
let valB = solution.evaluate(numB)
assert.equal(valA,8)
assert.equal(valB,6)
})
})