-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathtest.cjs
More file actions
38 lines (38 loc) · 1.27 KB
/
test.cjs
File metadata and controls
38 lines (38 loc) · 1.27 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
const Logic = require('./index.cjs')
const assert = require('assert')
const {describe, it} = require('node:test')
describe("Logic-solver cjs",()=>{
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)
})
})