Skip to content

Commit

Permalink
Merge pull request #217 from privacy-scaling-explorations/test/optimi…
Browse files Browse the repository at this point in the history
…ze-float

test(circuits): optimize `float.circom` tests
  • Loading branch information
cedoor committed Mar 18, 2024
2 parents eed8400 + 218f71f commit 7168dd4
Showing 1 changed file with 48 additions and 48 deletions.
96 changes: 48 additions & 48 deletions packages/circuits/tests/float.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ describe("float", () => {
circuit = await circomkit.WitnessTester("MSB", {
file: "float",
template: "MSB",
params: [252] // Assuming we're working within 252-bit numbers.
params: [2] // Assuming we're working within 2-bit numbers.
})

await circuit.expectFail(INPUT)
Expand All @@ -38,7 +38,7 @@ describe("float", () => {
circuit = await circomkit.WitnessTester("MSB", {
file: "float",
template: "MSB",
params: [252] // Assuming we're working within 252-bit numbers.
params: [2] // Assuming we're working within 2-bit numbers.
})

await circuit.expectPass(INPUT, OUTPUT)
Expand All @@ -50,7 +50,7 @@ describe("float", () => {

// Test values
const inValues = {
dividend: 10,
dividend: 1,
remainder: 1
}

Expand All @@ -68,7 +68,7 @@ describe("float", () => {
circuit = await circomkit.WitnessTester("Shift", {
file: "float",
template: "Shift",
params: [252] // Assuming we're working within 252-bit numbers.
params: [2] // Assuming we're working within 2-bit numbers.
})
})

Expand All @@ -95,7 +95,7 @@ describe("float", () => {
circuit = await circomkit.WitnessTester("IntegerDivision", {
file: "float",
template: "IntegerDivision",
params: [252] // Assuming we're working within 252-bit numbers.
params: [2] // Assuming we're working within 2-bit numbers.
})

await circuit.expectFail(INPUT)
Expand All @@ -116,7 +116,7 @@ describe("float", () => {
circuit = await circomkit.WitnessTester("IntegerDivision", {
file: "float",
template: "IntegerDivision",
params: [252] // Assuming we're working within 252-bit numbers.
params: [2] // Assuming we're working within 2-bit numbers.
})

await circuit.expectFail(INPUT)
Expand All @@ -126,7 +126,7 @@ describe("float", () => {
// Test values
const inValues = {
a: 0,
b: 10
b: 1
}
const expectedOut = 0

Expand All @@ -142,7 +142,7 @@ describe("float", () => {
circuit = await circomkit.WitnessTester("IntegerDivision", {
file: "float",
template: "IntegerDivision",
params: [252] // Assuming we're working within 252-bit numbers.
params: [2] // Assuming we're working within 2-bit numbers.
})

await circuit.expectPass(INPUT, OUTPUT)
Expand All @@ -168,7 +168,7 @@ describe("float", () => {
circuit = await circomkit.WitnessTester("IntegerDivision", {
file: "float",
template: "IntegerDivision",
params: [252] // Assuming we're working within 252-bit numbers.
params: [10] // Assuming we're working within 10-bit numbers.
})
await circuit.expectPass(INPUT, OUTPUT)
})
Expand All @@ -193,7 +193,7 @@ describe("float", () => {
circuit = await circomkit.WitnessTester("ToFloat", {
file: "float",
template: "ToFloat",
params: [2] // Assuming we're working within the range of 2^252.
params: [2] // Assuming we're working within the range of 2^2.
})
})

Expand All @@ -208,7 +208,7 @@ describe("float", () => {
it("Should throw when trying to perform division per zero [x, 0]", async () => {
// Test values
const inValues = {
a: 1000,
a: 1,
b: 0
}

Expand All @@ -220,7 +220,7 @@ describe("float", () => {
circuit = await circomkit.WitnessTester("DivisionFromFloat", {
file: "float",
template: "DivisionFromFloat",
params: [2, 251] // W decimal digits, N Assuming we're working within 252-bit numbers.
params: [2, 1] // W decimal digits, N Assuming we're working within 2-bit numbers.
})

await circuit.expectFail(INPUT)
Expand All @@ -229,8 +229,8 @@ describe("float", () => {
it("Should throw when trying to perform division per negative number [x, -x]", async () => {
// Test values
const inValues = {
a: 1000,
b: -1000
a: 1,
b: -1
}

const INPUT = {
Expand All @@ -241,7 +241,7 @@ describe("float", () => {
circuit = await circomkit.WitnessTester("DivisionFromFloat", {
file: "float",
template: "DivisionFromFloat",
params: [2, 251] // W decimal digits, N Assuming we're working within 252-bit numbers.
params: [2, 1] // W decimal digits, N Assuming we're working within 2-bit numbers.
})

await circuit.expectFail(INPUT)
Expand All @@ -251,7 +251,7 @@ describe("float", () => {
// Test values
const inValues = {
a: 0,
b: 1000
b: 1
}
const expectedOut = 0

Expand All @@ -267,7 +267,7 @@ describe("float", () => {
circuit = await circomkit.WitnessTester("DivisionFromFloat", {
file: "float",
template: "DivisionFromFloat",
params: [2, 251] // W decimal digits, N Assuming we're working within 252-bit numbers.
params: [2, 1] // W decimal digits, N Assuming we're working within 2-bit numbers.
})

await circuit.expectPass(INPUT, OUTPUT)
Expand All @@ -276,8 +276,8 @@ describe("float", () => {
it("Should correctly perform the integer division [x, y]", async () => {
// Test values
const inValues = {
a: 1000,
b: 200
a: 10,
b: 2
}
const expectedOut = 500

Expand All @@ -293,7 +293,7 @@ describe("float", () => {
circuit = await circomkit.WitnessTester("DivisionFromFloat", {
file: "float",
template: "DivisionFromFloat",
params: [2, 251] // W decimal digits, N Assuming we're working within 252-bit numbers.
params: [2, 31] // W decimal digits, N Assuming we're working within 32-bit numbers.
})

await circuit.expectPass(INPUT, OUTPUT)
Expand All @@ -306,7 +306,7 @@ describe("float", () => {
it("Should throw when trying to perform division per zero [x, 0]", async () => {
// Test values
const inValues = {
a: 10,
a: 1,
b: 0
}

Expand All @@ -318,7 +318,7 @@ describe("float", () => {
circuit = await circomkit.WitnessTester("DivisionFromNormal", {
file: "float",
template: "DivisionFromNormal",
params: [2, 251] // W decimal digits, N Assuming we're working within 252-bit numbers.
params: [2, 1] // W decimal digits, N Assuming we're working within 2-bit numbers.
})

await circuit.expectFail(INPUT)
Expand All @@ -327,8 +327,8 @@ describe("float", () => {
it("Should throw when trying to perform division per negative number [x, -x]", async () => {
// Test values
const inValues = {
a: 10,
b: -10
a: 1,
b: -1
}

const INPUT = {
Expand All @@ -339,7 +339,7 @@ describe("float", () => {
circuit = await circomkit.WitnessTester("DivisionFromNormal", {
file: "float",
template: "DivisionFromNormal",
params: [2, 251] // W decimal digits, N Assuming we're working within 252-bit numbers.
params: [2, 1] // W decimal digits, N Assuming we're working within 2-bit numbers.
})

await circuit.expectFail(INPUT)
Expand All @@ -349,7 +349,7 @@ describe("float", () => {
// Test values
const inValues = {
a: 0,
b: 10
b: 1
}
const expectedOut = 0

Expand All @@ -365,7 +365,7 @@ describe("float", () => {
circuit = await circomkit.WitnessTester("DivisionFromNormal", {
file: "float",
template: "DivisionFromNormal",
params: [2, 251] // W decimal digits, N Assuming we're working within 252-bit numbers.
params: [2, 31] // W decimal digits, N Assuming we're working within 32-bit numbers.
})

await circuit.expectPass(INPUT, OUTPUT)
Expand All @@ -391,7 +391,7 @@ describe("float", () => {
circuit = await circomkit.WitnessTester("DivisionFromNormal", {
file: "float",
template: "DivisionFromNormal",
params: [2, 251] // W decimal digits, N Assuming we're working within 252-bit numbers.
params: [2, 31] // W decimal digits, N Assuming we're working within 32-bit numbers.
})

await circuit.expectPass(INPUT, OUTPUT)
Expand All @@ -404,8 +404,8 @@ describe("float", () => {
it("Should throw when trying to perform multiplication per negative number [-x, x]", async () => {
// Test values
const inValues = {
a: -100,
b: 100
a: -1,
b: 1
}

const INPUT = {
Expand All @@ -416,7 +416,7 @@ describe("float", () => {
circuit = await circomkit.WitnessTester("MultiplicationFromFloat", {
file: "float",
template: "MultiplicationFromFloat",
params: [2, 251] // W decimal digits, N Assuming we're working within 252-bit numbers.
params: [2, 31] // W decimal digits, N Assuming we're working within 32-bit numbers.
})

await circuit.expectFail(INPUT)
Expand All @@ -442,7 +442,7 @@ describe("float", () => {
circuit = await circomkit.WitnessTester("MultiplicationFromFloat", {
file: "float",
template: "MultiplicationFromFloat",
params: [2, 251] // W decimal digits, N Assuming we're working within 252-bit numbers.
params: [2, 31] // W decimal digits, N Assuming we're working within 32-bit numbers.
})

await circuit.expectPass(INPUT, OUTPUT)
Expand All @@ -451,7 +451,7 @@ describe("float", () => {
it("Should correctly perform the multiplication from float [x, 0]", async () => {
// Test values
const inValues = {
a: 100,
a: 1,
b: 0
}
const expectedOut = 0
Expand All @@ -468,7 +468,7 @@ describe("float", () => {
circuit = await circomkit.WitnessTester("MultiplicationFromFloat", {
file: "float",
template: "MultiplicationFromFloat",
params: [2, 251] // W decimal digits, N Assuming we're working within 252-bit numbers.
params: [2, 31] // W decimal digits, N Assuming we're working within 32-bit numbers.
})

await circuit.expectPass(INPUT, OUTPUT)
Expand All @@ -478,7 +478,7 @@ describe("float", () => {
// Test values
const inValues = {
a: 0,
b: 100
b: 1
}
const expectedOut = 0

Expand All @@ -494,7 +494,7 @@ describe("float", () => {
circuit = await circomkit.WitnessTester("MultiplicationFromFloat", {
file: "float",
template: "MultiplicationFromFloat",
params: [2, 251] // W decimal digits, N Assuming we're working within 252-bit numbers.
params: [2, 31] // W decimal digits, N Assuming we're working within 32-bit numbers.
})

await circuit.expectPass(INPUT, OUTPUT)
Expand All @@ -503,10 +503,10 @@ describe("float", () => {
it("Should correctly perform the multiplication from float [x, y]", async () => {
// Test values
const inValues = {
a: 100,
b: 200
a: 10,
b: 20
}
const expectedOut = 200
const expectedOut = 2

const INPUT = {
a: inValues.a,
Expand All @@ -520,7 +520,7 @@ describe("float", () => {
circuit = await circomkit.WitnessTester("MultiplicationFromFloat", {
file: "float",
template: "MultiplicationFromFloat",
params: [2, 251] // W decimal digits, N Assuming we're working within 252-bit numbers.
params: [2, 31] // W decimal digits, N Assuming we're working within 32-bit numbers.
})

await circuit.expectPass(INPUT, OUTPUT)
Expand All @@ -545,7 +545,7 @@ describe("float", () => {
circuit = await circomkit.WitnessTester("MultiplicationFromNormal", {
file: "float",
template: "MultiplicationFromNormal",
params: [2, 251] // W decimal digits, N Assuming we're working within 252-bit numbers.
params: [2, 31] // W decimal digits, N Assuming we're working within 32-bit numbers.
})

await circuit.expectFail(INPUT)
Expand All @@ -571,7 +571,7 @@ describe("float", () => {
circuit = await circomkit.WitnessTester("MultiplicationFromNormal", {
file: "float",
template: "MultiplicationFromNormal",
params: [2, 251] // W decimal digits, N Assuming we're working within 252-bit numbers.
params: [2, 31] // W decimal digits, N Assuming we're working within 32-bit numbers.
})

await circuit.expectPass(INPUT, OUTPUT)
Expand All @@ -597,7 +597,7 @@ describe("float", () => {
circuit = await circomkit.WitnessTester("MultiplicationFromNormal", {
file: "float",
template: "MultiplicationFromNormal",
params: [2, 251] // W decimal digits, N Assuming we're working within 252-bit numbers.
params: [2, 31] // W decimal digits, N Assuming we're working within 32-bit numbers.
})

await circuit.expectPass(INPUT, OUTPUT)
Expand All @@ -623,7 +623,7 @@ describe("float", () => {
circuit = await circomkit.WitnessTester("MultiplicationFromNormal", {
file: "float",
template: "MultiplicationFromNormal",
params: [2, 251] // W decimal digits, N Assuming we're working within 252-bit numbers.
params: [2, 31] // W decimal digits, N Assuming we're working within 32-bit numbers.
})

await circuit.expectPass(INPUT, OUTPUT)
Expand All @@ -632,10 +632,10 @@ describe("float", () => {
it("Should correctly perform the multiplication from float [x, y]", async () => {
// Test values
const inValues = {
a: 1,
b: 2
a: 10,
b: 20
}
const expectedOut = 200
const expectedOut = 20000

const INPUT = {
a: inValues.a,
Expand All @@ -649,7 +649,7 @@ describe("float", () => {
circuit = await circomkit.WitnessTester("MultiplicationFromNormal", {
file: "float",
template: "MultiplicationFromNormal",
params: [2, 251] // W decimal digits, N Assuming we're working within 252-bit numbers.
params: [2, 31] // W decimal digits, N Assuming we're working within 32-bit numbers.
})

await circuit.expectPass(INPUT, OUTPUT)
Expand Down

0 comments on commit 7168dd4

Please sign in to comment.