-
Notifications
You must be signed in to change notification settings - Fork 24
/
Copy pathplain-modulus.test.ts
65 lines (63 loc) · 2.62 KB
/
plain-modulus.test.ts
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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
import { EncryptionParameters } from '../implementation/encryption-parameters'
import { SEALLibrary } from '../implementation/seal'
import SEAL from '../throws_wasm_node_umd'
let seal: SEALLibrary
let parms: EncryptionParameters
beforeAll(async () => {
seal = await SEAL()
parms = seal.EncryptionParameters(seal.SchemeType.bfv)
parms.setPolyModulusDegree(4096)
parms.setCoeffModulus(
seal.CoeffModulus.BFVDefault(4096, seal.SecurityLevel.tc128)
)
parms.setPlainModulus(seal.PlainModulus.Batching(4096, 20))
})
describe('PlainModulus', () => {
test('It should be a static instance', () => {
expect(seal.PlainModulus).toBeDefined()
expect(typeof seal.PlainModulus.constructor).toBe('function')
expect(seal.PlainModulus).toBeInstanceOf(Object)
expect(seal.PlainModulus.constructor).toBe(Object)
expect(seal.PlainModulus.constructor.name).toBe('Object')
})
test('It should have properties', () => {
// Test properties
expect(seal.PlainModulus).toHaveProperty('Batching')
expect(seal.PlainModulus).toHaveProperty('BatchingVector')
})
test('It should a return a Modulus', () => {
const spyOn = jest.spyOn(seal.PlainModulus, 'Batching')
const modulus = seal.PlainModulus.Batching(4096, 20)
expect(spyOn).toHaveBeenCalledWith(4096, 20)
expect(modulus).toBeDefined()
expect(typeof modulus.constructor).toBe('function')
expect(modulus).toBeInstanceOf(Object)
expect(modulus.constructor).toBe(Object)
expect(modulus.constructor.name).toBe('Object')
expect(modulus.instance.constructor.name).toBe('Modulus')
})
test('It should fail to return a Modulus', () => {
const spyOn = jest.spyOn(seal.PlainModulus, 'Batching')
expect(() => seal.PlainModulus.Batching(4095, 20)).toThrow()
expect(spyOn).toHaveBeenCalledWith(4095, 20)
})
test('It should a create a Vector of Modulus', () => {
const spyOn = jest.spyOn(seal.PlainModulus, 'BatchingVector')
const vectModulus = seal.PlainModulus.BatchingVector(
4096,
Int32Array.from([20, 20, 20])
)
expect(spyOn).toHaveBeenCalledWith(4096, Int32Array.from([20, 20, 20]))
expect(vectModulus).toBeDefined()
expect(typeof vectModulus.constructor).toBe('function')
expect(vectModulus).toBeInstanceOf(Object)
expect(vectModulus.constructor.name).toBe('std::vector<Modulus>')
})
test('It should fail to create a Vector of Modulus', () => {
const spyOn = jest.spyOn(seal.PlainModulus, 'BatchingVector')
expect(() =>
seal.PlainModulus.BatchingVector(4095, Int32Array.from([20, 20, 20]))
).toThrow()
expect(spyOn).toHaveBeenCalledWith(4095, Int32Array.from([20, 20, 20]))
})
})