Skip to content

Commit

Permalink
var to let
Browse files Browse the repository at this point in the history
  • Loading branch information
Snafkin547 committed Apr 4, 2024
1 parent 3581a78 commit 552f173
Show file tree
Hide file tree
Showing 8 changed files with 79 additions and 79 deletions.
10 changes: 5 additions & 5 deletions tests/regr-tests/arithmetics.test.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
describe('JIFF Arithmetic Operations', () => {
var jiffClients: any[] = [];
var jiffServer: any;
var server: any;
let jiffClients: any[] = [];
let jiffServer: any;
let server: any;
const entries: { [key: number]: number } = { 1: 60.05, 2: 60.05 };
var computation_id = 'test-arithmetics';
let computation_id = 'test-arithmetics';
const party_count = 2;

beforeEach(async () => {
// Server Setup
var port: number = 8111;
let port: number = 8111;
const init_server = require('./server');
const jiff_s_bignumber = require('../../lib/ext/jiff-server-bignumber.js');
const extensions = [jiff_s_bignumber];
Expand Down
32 changes: 16 additions & 16 deletions tests/regr-tests/array.test.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
describe('JIFF Array Operations', () => {
var jiffClients: any[] = [];
var jiffServer: any;
var server: any;
let jiffClients: any[] = [];
let jiffServer: any;
let server: any;
const entries: number[] = [1, 4, 8, 10, 12, 16, 17, 23, 29];
const input: number = 4;
const computation_id = 'test-array';
const party_count = 2;

beforeEach(async () => {
// Server Setup
var port: number = 8113;
let port: number = 8113;
const init_server = require('./server');
const servers = init_server(port);
(jiffServer = servers[0]), (server = servers[1]);
Expand Down Expand Up @@ -44,10 +44,10 @@ describe('JIFF Array Operations', () => {
return new Promise((resolve, reject) => {
jiffClient.wait_for([1, 2], async () => {
try {
var array = await jiffClient.share_array(arrays[id]);
var result = await array[1];
for (var party = 2; party <= jiffClient.party_count; party++) {
for (var idx = 0; idx < result.length; idx++) {
let array = await jiffClient.share_array(arrays[id]);
let result = await array[1];
for (let party = 2; party <= jiffClient.party_count; party++) {
for (let idx = 0; idx < result.length; idx++) {
result[idx] = await result[idx].add(await array[party][idx]);
}
}
Expand All @@ -69,7 +69,7 @@ describe('JIFF Array Operations', () => {
return new Promise((resolve, reject) => {
jiffClient.wait_for([1, 2], async () => {
try {
var arrayToShare = null;
let arrayToShare = null;
if (id == 1) {
arrayToShare = entries;
} else {
Expand All @@ -79,12 +79,12 @@ describe('JIFF Array Operations', () => {
const array = await inputs[1];
const element = await inputs[2];

var occurrences = await array[0].eq(element);
for (var i = 1; i < array.length; i++) {
let occurrences = await array[0].eq(element);
for (let i = 1; i < array.length; i++) {
const check = await array[i].eq(element);
occurrences = await occurrences.add(check);
}
var result = await occurrences.gteq(1);
let result = await occurrences.gteq(1);
result = await jiffClient.open(result);
resolve(result.toString(10));
} catch (error) {
Expand All @@ -103,7 +103,7 @@ describe('JIFF Array Operations', () => {
return new Promise((resolve, reject) => {
jiffClient.wait_for([1, 2], async () => {
try {
var whichArray = null;
let whichArray = null;
if (id == 1) {
whichArray = entries;
} else {
Expand All @@ -120,8 +120,8 @@ describe('JIFF Array Operations', () => {

const mid = Math.floor(array.length / 2);
const cmp = await element.lt(await array[mid]);
var nArray = [];
for (var i = 0; i < mid; i++) {
let nArray = [];
for (let i = 0; i < mid; i++) {
const c1 = array[i];
const c2 = array[mid + i];
nArray[i] = await cmp.if_else(c1, c2);
Expand All @@ -133,7 +133,7 @@ describe('JIFF Array Operations', () => {
}

const occurrences = await _bin_search(array, elem);
var result = await occurrences.gteq(1);
let result = await occurrences.gteq(1);
result = await jiffClient.open(result);
resolve(result.toString(10));
} catch (error) {
Expand Down
12 changes: 6 additions & 6 deletions tests/regr-tests/bit-preprocess.test.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
describe('JIFF Preprocessing Operations', () => {
var jiffClients: any[] = [];
var jiffServer: any;
var server: any;
let jiffClients: any[] = [];
let jiffServer: any;
let server: any;
const entries: { [key: number]: number } = { 1: 60, 2: 50 };
var computation_id = 'test-bit-preprocessing';
let computation_id = 'test-bit-preprocessing';
const party_count = 2;

beforeEach(async () => {
// Server Setup
var port: number = 8115;
let port: number = 8115;
const init_server = require('./server');
const jiff_s_bignumber = require('../../lib/ext/jiff-server-bignumber.js');
const extensions = [jiff_s_bignumber];
Expand Down Expand Up @@ -53,7 +53,7 @@ describe('JIFF Preprocessing Operations', () => {
try {
const jiff_bits = await jiffClient.protocols.bits;
const input = await jiff_bits.share(entries[id]);
var sec_ttl = await jiff_bits.smult(await input[1], await input[2]);
let sec_ttl = await jiff_bits.smult(await input[1], await input[2]);
const result = await jiff_bits.open(sec_ttl);
resolve(result.toString(10));
} catch (error) {
Expand Down
14 changes: 7 additions & 7 deletions tests/regr-tests/bitwise-comp.test.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
describe('JIFF bitshare Comparison', () => {
var jiffClients: any[] = [];
var jiffServer: any;
var server: any;
let jiffClients: any[] = [];
let jiffServer: any;
let server: any;
const entries: { [key: number]: number } = { 1: 60, 2: 50 };
var computation_id = 'test-bitshare-comparison';
let computation_id = 'test-bitshare-comparison';
const party_count = 2;

beforeEach(async () => {
// Server Setup
var port: number = 8117;
let port: number = 8117;
const init_server = require('./server');
const jiff_s_bignumber = require('../../lib/ext/jiff-server-bignumber.js');
const extensions = [jiff_s_bignumber];
Expand Down Expand Up @@ -53,7 +53,7 @@ describe('JIFF bitshare Comparison', () => {
const comp1 = await jiff_bits.seq(input1, input[2]);
const sec_ttl = await jiff_bits.sadd(await input[1], await input[2]);
const comp2 = await jiff_bits.ceq(sec_ttl, 110);
var result = await comp1.smult(comp2);
let result = await comp1.smult(comp2);
result = await result.open();
resolve(result.toString(10));
} catch (error) {
Expand All @@ -77,7 +77,7 @@ describe('JIFF bitshare Comparison', () => {
const comp1 = await jiff_bits.sneq(input[1], input[2]);
const sec_ttl = await jiff_bits.sadd(input[1], input[2]);
const comp2 = await jiff_bits.cneq(sec_ttl, 120);
var result = await comp1.smult(comp2);
let result = await comp1.smult(comp2);
result = await result.open();
resolve(result.toString(10));
} catch (error) {
Expand Down
20 changes: 10 additions & 10 deletions tests/regr-tests/bitwise-ops.test.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
describe('JIFF bitwise Arithmetic Operations', () => {
var jiffClients: any[] = [];
var jiffServer: any;
var server: any;
let jiffClients: any[] = [];
let jiffServer: any;
let server: any;
const entries: { [key: number]: number } = { 1: 60, 2: 50 };
var computation_id = 'test-bitwisse-ops';
let computation_id = 'test-bitwisse-ops';
const party_count = 2;

beforeEach(async () => {
// Server Setup
var port: number = 8116;
let port: number = 8116;
const init_server = require('./server');
const jiff_s_bignumber = require('../../lib/ext/jiff-server-bignumber.js');
const extensions = [jiff_s_bignumber];
Expand Down Expand Up @@ -53,7 +53,7 @@ describe('JIFF bitwise Arithmetic Operations', () => {
try {
const jiff_bits = await jiffClient.protocols.bits;
const input = await jiff_bits.share(entries[id]);
var sec_ttl = await jiff_bits.sadd(await input[1], await input[2]);
let sec_ttl = await jiff_bits.sadd(await input[1], await input[2]);
sec_ttl = await jiff_bits.cadd(sec_ttl, 10);
const result = await jiff_bits.open(sec_ttl);
resolve(result.toString(10));
Expand All @@ -75,7 +75,7 @@ describe('JIFF bitwise Arithmetic Operations', () => {
try {
const jiff_bits = await jiffClient.protocols.bits;
const input = await jiff_bits.share(entries[id]);
var sec_ttl = await jiff_bits.ssub(await input[1], await input[2]);
let sec_ttl = await jiff_bits.ssub(await input[1], await input[2]);
sec_ttl = await jiff_bits.csubl(sec_ttl, 10);
sec_ttl = await jiff_bits.csubr(100, sec_ttl);
const result = await jiff_bits.open(sec_ttl);
Expand All @@ -98,7 +98,7 @@ describe('JIFF bitwise Arithmetic Operations', () => {
try {
const jiff_bits = await jiffClient.protocols.bits;
const input = await jiff_bits.share(entries[id]);
var sec_ttl = await jiff_bits.smult(input[1], input[2]);
let sec_ttl = await jiff_bits.smult(input[1], input[2]);
const result = await jiff_bits.open(sec_ttl);
resolve(result.toString(10));
} catch (error) {
Expand All @@ -119,12 +119,12 @@ describe('JIFF bitwise Arithmetic Operations', () => {
try {
const jiff_bits = await jiffClient.protocols.bits;
const input = await jiff_bits.share(entries[id]);
var sec_ttl = await jiff_bits.sdiv(await input[1], await input[2]);
let sec_ttl = await jiff_bits.sdiv(await input[1], await input[2]);
const bit_quotient = await sec_ttl['quotient'];
const bit_remainder = await sec_ttl['remainder'];

const int_quotient = await jiff_bits.open(bit_quotient);
var int_remainder = await jiff_bits.open(bit_remainder);
let int_remainder = await jiff_bits.open(bit_remainder);
int_remainder = await int_remainder.toString(10);
const frac_remainder = parseInt(int_remainder) / entries[2];
const result = parseInt(await int_quotient.toString(10), 10) + frac_remainder;
Expand Down
18 changes: 9 additions & 9 deletions tests/regr-tests/preprocess.test.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
describe('JIFF Preprocessing Operations', () => {
var jiffClients: any[] = [];
var jiffServer: any;
var server: any;
let jiffClients: any[] = [];
let jiffServer: any;
let server: any;
const entries: { [key: number]: number[] | null[] } = { 1: [1.32, 10.22, 5.67], 2: [5.91, 3.73, 50.03], 3: [null, null, null] };
var computation_id = 'test-preprocessing';
let computation_id = 'test-preprocessing';
const party_count = 3;

beforeEach(async () => {
// Server Setup
var port: number = 8115;
let port: number = 8115;
const init_server = require('./server');
const jiff_s_bignumber = require('../../lib/ext/jiff-server-bignumber.js');
const extensions = [jiff_s_bignumber];
Expand Down Expand Up @@ -51,13 +51,13 @@ describe('JIFF Preprocessing Operations', () => {
return new Promise((resolve, reject) => {
jiffClient.wait_for([1, 2, 3], async () => {
try {
var sec_ttl: any = 0;
let sec_ttl: any = 0;
await jiffClient.executePreprocessing(async function () {
const input = await jiffClient.share_array(entries[id], null, 3, [1, 2, 3], [1, 2]);
var array1 = input[1];
var array2 = input[2];
let array1 = input[1];
let array2 = input[2];
sec_ttl = await array1[0].mult(array2[0], null, false);
for (var i = 1; i < array1.length; i++) {
for (let i = 1; i < array1.length; i++) {
sec_ttl = await sec_ttl.add(await array1[i].mult(array2[i], null, false));
}
const result = await sec_ttl.open();
Expand Down
18 changes: 9 additions & 9 deletions tests/regr-tests/statistics.test.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
describe('JIFF Statistics Operations', () => {
var jiffClients: any[] = [];
var jiffServer: any;
var server: any;
let jiffClients: any[] = [];
let jiffServer: any;
let server: any;
const entries: { [key: number]: number } = { 1: 60, 2: 60, 3: 60, 4: 60 };
var computation_id = 'test-stats';
let computation_id = 'test-stats';
const party_count = 4;

beforeEach(async () => {
// Server Setup
var port: number = 8114;
let port: number = 8114;
const init_server = require('./server');
const jiff_s_bignumber = require('../../lib/ext/jiff-server-bignumber.js');
const extensions = [jiff_s_bignumber];
Expand Down Expand Up @@ -48,14 +48,14 @@ describe('JIFF Statistics Operations', () => {
});

async function average(jiffclient: any, input: number) {
var sshare = await jiffclient.share(input);
var sec_sum = sshare[1];
for (var i = 2; i <= jiffclient.party_count; i++) {
let sshare = await jiffclient.share(input);
let sec_sum = sshare[1];
for (let i = 2; i <= jiffclient.party_count; i++) {
jiffclient.start_barrier();
sec_sum = await sec_sum.add(sshare[i]);
jiffclient.end_barrier();
}
var result = await sec_sum.open();
let result = await sec_sum.open();
return result.toString(10) / jiffclient.party_count;
}

Expand Down
34 changes: 17 additions & 17 deletions tests/regr-tests/vote.test.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
describe('JIFF Voting', () => {
var jiffClients: any[] = [];
var jiffServer: any;
var server: any;
let jiffClients: any[] = [];
let jiffServer: any;
let server: any;
const entries: { [key: number]: number[] } = { 1: [1, 0, 0, 0], 2: [0, 0, 0, 1], 3: [0, 0, 0, 1] };
var computation_id = 'test-voting';
let computation_id = 'test-voting';
const party_count = 3;

beforeEach(async () => {
Expand Down Expand Up @@ -44,15 +44,15 @@ describe('JIFF Voting', () => {
it('should correctly find the majority vote', async () => {
async function sanityCheck(shares: any) {
// first check: if sum of values in an array/share = 1
var sum = shares[0];
for (var i = 1; i < shares.length; i++) {
let sum = shares[0];
for (let i = 1; i < shares.length; i++) {
sum = await sum.add(shares[i]);
}
var check1 = await sum.eq(1);
let check1 = await sum.eq(1);

// second check: if all elements are <= 1
var check2 = await shares[0].lteq(1);
for (var j = 1; j < shares.length; j++) {
let check2 = await shares[0].lteq(1);
for (let j = 1; j < shares.length; j++) {
check2 = await check2.smult(shares[j].lteq(1));
}

Expand All @@ -69,23 +69,23 @@ describe('JIFF Voting', () => {
const checker1 = await sanityCheck(input[1]);
const checker2 = await sanityCheck(input[2]);
const checker3 = await sanityCheck(input[3]);
var sanity_flag = await checker1.add(checker2);
let sanity_flag = await checker1.add(checker2);
sanity_flag = await sanity_flag.add(checker3);
sanity_flag = await sanity_flag.eq(3);

// Aggregating all votes into the array named 'vote'
var vote = input[1];
for (var party = 2; party <= jiffClient.party_count; party++) {
for (var idx = 0; idx < vote.length; idx++) {
let vote = input[1];
for (let party = 2; party <= jiffClient.party_count; party++) {
for (let idx = 0; idx < vote.length; idx++) {
vote[idx] = await vote[idx].add(input[party][idx]);
}
}

// Check who's got the majority vote
var majo_idx = 0;
var curr_max = vote[0];
for (var i = 1; i < vote.length; i++) {
var iIsMax = await vote[i].gt(curr_max);
let majo_idx = 0;
let curr_max = vote[0];
for (let i = 1; i < vote.length; i++) {
let iIsMax = await vote[i].gt(curr_max);
majo_idx = await iIsMax.if_else(i, majo_idx);
}
majo_idx = await sanity_flag.if_else(majo_idx, -1);
Expand Down

0 comments on commit 552f173

Please sign in to comment.