diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 0000000..61679f2 --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,2 @@ +{"editor.minimap.enabled": false +} \ No newline at end of file diff --git a/election-part2.js b/election-part2.js index 464babb..9a26fe6 100644 --- a/election-part2.js +++ b/election-part2.js @@ -1,43 +1,169 @@ // Importing the functions from what you did in part 1. -const { - candidatesObjToArray, - filterInvalidVoters, - runElection, - getWinner, - winnerMessage, -} = require('./election'); +// const { +// candidatesObjToArray, +// filterInvalidVoters, +// runElection, +// getWinner, +// winnerMessage, +// } = require('./election'); +function candidatesObjToArray(candidates) { + var arrOfKeys = Object.keys(candidates); + var arrOfCandidates = arrOfKeys.map(function (key) { return candidates[key] }); + return arrOfCandidates; +} /** - * 1 - Write a Voter class modelling a member of the population who votes in the election. + * 2 - Remove any voters who have voted for more than 2 people, or have voted for the same person twice. +*/ +function filterInvalidVoters(allVoters) { + const filteredByLength = allVoters.filter(item => item.votingCard.length < 3); + const filteredByClash = filteredByLength.filter(item => item.votingCard[0] !== item.votingCard[1]) + return filteredByClash; +} +/** + * 3 - Add up all the votes cast by the voting population. Note that for two adjacent votes in the vote array, + * the right vote counts for half of the left vote. */ - - +//refactored Version of runElection +function runElection(validVoters, candidates) { + for (let i = 0; i < candidates.length; i++) { + validVoters.forEach(function (item) { + //console.log(can); + if (item.votingCard[0] === i) { + candidates[i].numVotes += 1 + } + if (item.votingCard[1] === i) + candidates[i].numVotes += 0.5; + }) + } + return candidates; +} +/** + * 4 - After an election has been run, return the winner + * + * Desired return value: {name: "Tamara Faiza", age: 46, party: "Pizza Party", numVotes: 3} + */ +function getWinner(candidates) { + candidates.sort(function(a,b) {return b.numVotes-a.numVotes}) + //check if two candidates have the same numVotes we have to return null-draw + if (candidates[0].numVotes===candidates[1].numVotes) {return null;} + return candidates[0]; //Hila Waraich won with 26.5 votes +} +/** + * 5 - Return a message including the name of the winner, and how many votes + * he/she received + */ +function winnerMessage(winner) { + var winner = getWinner(candidates) + if (winner !== null) { + var mes = winner.name + " has won the election with " + winner.numVotes + " votes!"; + return mes; + } + else return "The election was a draw"; +} + +/* 1 - Write a Voter class modelling a member of the population who votes in the election. +*/ +class Voter { + constructor(name, age, votingCard) { + this.name = name; + this.age = age; + this.votingCard = votingCard; + } +} +let votingPopulation = [ + new Voter('Jane Finnegan', 19, [1, 3]), + new Voter('Norman Beracha', 35, [3, 4]), + new Voter('Salome Kadek', 22, [2, 1, 3]), + new Voter('Wei Li', 19, [1, 2]), + new Voter('Sam MacKinnon', 59, [1, 4]) +] /** * 2 - Write a Candidate class modelling a candidate in the election. Candidates are also voters (they can vote for themselves, or anyone else). * However they have some extra properties. */ - - +class Candidate extends Voter { + constructor(name, age, party, votingCard) { + super(name, age, votingCard); + this.party = party; + this.numVotes = 0; + } +} +let candidates = { + 1: new Candidate('Tamara Faiza', 46, 'Pizza Party', [1, 1]), + 2: new Candidate('Aylin Duke', 39, 'Foam Party', [2, 2]), + 3: new Candidate('Clay Roderick', 54, 'Flat Earth Party', [3, 4]), + 4: new Candidate('Nour al-Din', 32, 'Pizza Party', [4, 1]) +} /** * 3 - Write an Election class which models the election. */ +class Election { + constructor(validVoters, candidates) { + this.validVoters = validVoters; + //console.log(validVoters, "validVoters in class"); + this.candidates = candidates; + this.winner = 'winner has not been chosen yet'; + } + runElection() { + + this.candidates = runElection(this.validVoters, this.candidates) + + + } getWinner() { + //console.log("getwinner is getting called") + this.winner = getWinner(this.candidates); + + } printWinnerMessage() { + //console.log("this is bug message",this.winner) + if (this.winner === null) { return "The election was a draw"; } + return this.winner.name + " has won the election with " + this.winner.numVotes + " votes!"; + } +} +// Example of how the winner message can be printed. + +/* +fetch('http://www.mocky.io/v2/5a55224b2d000088425b1ed8') + .then(function (response) { return response.json() }) + .then(function (json) { console.log(json); }) */ + +//list of Candidates +let listCan = document.querySelectorAll(".candidates li"); +// listCan[0].textContent=candidates["1"].name; +// listCan[1].textContent=candidates["2"].name; +// listCan[2].textContent=candidates["3"].name; +// listCan[3].textContent=candidates["4"].name; + +//listCan.forEach((item,i,candidates)=>item[i].textContent=candidates[i+1].name); //?????solved +listCan.forEach((item, i, listCan) => item.textContent = candidates[i + 1].name) +// for (let i = 0; i < listCan.length; i++) { +// listCan[i].textContent = candidates[i + 1].name; +// } +//list of Voters +let listVote = document.querySelectorAll(".voters li"); +listVote.forEach((item, i, listVote) => item.textContent = votingPopulation[i].name); + +//run Election Buttun +let runButt = document.getElementById("runBut"); +runButt.addEventListener("click", () => fetchElectionData().then(message=>alert(message))); + +function fetchElectionData() { + var data; + //return 2; + return fetch('https://s3-eu-west-1.amazonaws.com/lorenzomixedstuff/electionList.json').then(res => res.json()).then(function (jsonData) { + data = jsonData; + candidates = data.candidates.map(function (item) { return new Candidate(item.name, item.age, item.party, item.votingCard) }); + voters = data.voters; + let allVoters = voters.concat(candidates); + let validVoters = filterInvalidVoters(allVoters); + + let election = new Election(validVoters, candidates); + election.runElection(); // Example of how runElection() can be called. + election.getWinner(); //need to modify it so it becomes a sort only selects max numVotes + var message = election.printWinnerMessage(); + return message; + } + ) +} - -// Include your votingPopulation array here. -let votingPopulation = []; - - -// Include your candidates object here. -let candidates = {}; - - -let allVoters = votingPopulation.concat(candidatesObjToArray(candidates)); - -let validVoters = filterInvalidVoters(allVoters); - -let election = new Election(validVoters, candidates); - -election.runElection(); // Example of how runElection() can be called. - -console.log(election.printWinnerMessage()); // Example of how the winner message can be printed. diff --git a/election.js b/election.js index 776f3a1..c3862b8 100644 --- a/election.js +++ b/election.js @@ -6,72 +6,110 @@ * 1 - Convert candidates object to array */ function candidatesObjToArray(candidates) { - + var arrOfKeys = Object.keys(candidates); + var arrOfCandidates = arrOfKeys.map(function (key) { return candidates[key]; }); + return arrOfCandidates; } /** * 2 - Remove any voters who have voted for more than 2 people, or have voted for the same person twice. */ -function filterInvalidVoters(voters) { +function filterInvalidVoters(allVoters) { + return allVoters.filter(item => item.votingCard.length < 3 && item.votingCard[0] !== item.votingCard[1] + ) } - /** * 3 - Add up all the votes cast by the voting population. Note that for two adjacent votes in the vote array, * the right vote counts for half of the left vote. */ -function runElection(voters, candidates) { - +//refactored Version of runElection +function runElection(validVoters, candidates) { + for (let i = 1; i < Object.values(candidates).length; i++) { + validVoters.forEach(function (item) { + if (item.votingCard[0] === i) { + candidates[i].numVotes += 1 + } + if (item.votingCard[1] === i) + candidates[i].numVotes += 0.5; + }) + } + return candidates; } - /** * 4 - After an election has been run, return the winner * * Desired return value: {name: "Tamara Faiza", age: 46, party: "Pizza Party", numVotes: 3} */ function getWinner(candidates) { - + let winner = { numVotes: 0.0 }; + try { + Object.values(candidates).forEach(function (item) { + /* console.log(item.name,item.numVotes); + console.log(winner.name,winner.numVotes); + console.log(); */ + if (item.numVotes == winner.numVotes) { + throw "Duplicate"; + } + else if (item.numVotes > winner.numVotes) { + winner = item; + } + }) + } catch (error) { + return null; + } + return winner; } - /** * 5 - Return a message including the name of the winner, and how many votes * he/she received */ function winnerMessage(winner) { - + var winner = getWinner(candidates) + if (winner !== null) { + var mes = winner.name + " has won the election with " + winner.numVotes + " votes!"; + return mes; + } + else return "The election was a draw"; } // A sample population of a small number of voters, stored as an array let votingPopulation = [ - {name: 'Jane Finnegan', age: 19, votingCard: [1,3]}, - {name: 'Norman Beracha', age: 35, votingCard: [3,4]}, - {name: 'Salome Kadek', age: 22, votingCard: [2,1,3]}, - {name: 'Wei Li', age: 19, votingCard: [1,2]}, - {name: 'Sam MacKinnon', age: 59, votingCard: [1,4]} + { name: 'Jane Finnegan', age: 19, votingCard: [1, 3] }, + { name: 'Norman Beracha', age: 35, votingCard: [3, 4] }, + { name: 'Salome Kadek', age: 22, votingCard: [2, 1, 3] }, + { name: 'Wei Li', age: 19, votingCard: [1, 2] }, + { name: 'Sam MacKinnon', age: 59, votingCard: [1, 4] } ]; // The election candidates, stored as an object where each object key is the candidate ID, and the object // value is the candidate object itself. let candidates = { - 1: {name: 'Tamara Faiza', age: 46, votingCard: [1,1], party: 'Pizza Party', numVotes: 0}, - 2: {name: 'Aylin Duke', age: 39, votingCard: [2,2], party: 'Foam Party', numVotes: 0}, - 3: {name: 'Clay Roderick', age: 54, votingCard: [3,4], party: 'Flat Earth Party', numVotes: 0}, - 4: {name: 'Nour al-Din', age: 32, votingCard: [4,1], party: 'Pizza Party', numVotes: 0} -}; + 1: { name: 'Tamara Faiza', age: 46, votingCard: [1, 1], party: 'Pizza Party', numVotes: 0 }, + 2: { name: 'Aylin Duke', age: 39, votingCard: [2, 2], party: 'Foam Party', numVotes: 0 }, + 3: { name: 'Clay Roderick', age: 54, votingCard: [3, 4], party: 'Flat Earth Party', numVotes: 0 }, + 4: { name: 'Nour al-Din', age: 32, votingCard: [4, 1], party: 'Pizza Party', numVotes: 0 } +} //4,3 is draw let allVoters = votingPopulation.concat(candidatesObjToArray(candidates)); +//console.log(allVoters); let validVoters = filterInvalidVoters(allVoters); +//console.log(validVoters,"validdddddddddd") //--> array of Objects candidates = runElection(validVoters, candidates); +//console.log(candidates); let winner = getWinner(candidates); +//console.log("and the winner is: ",winner) + +console.log(winnerMessage()); module.exports = { - candidatesObjToArray, - filterInvalidVoters, - runElection, - getWinner, - winnerMessage + candidatesObjToArray, + filterInvalidVoters, + runElection, + getWinner, + winnerMessage } diff --git a/election.test.js b/election.test.js index 75efd0b..f1f3864 100644 --- a/election.test.js +++ b/election.test.js @@ -56,6 +56,16 @@ test('getWinner should return the winning candidate', () => { numVotes: 3.5, }) }) +test('getWinner should return the winning candidate', () => { + const candidatesAfterElection = { + 1: {name:"Tamara Faiza",age:46,votingCard:[1,1],party:"Pizza Party",numVotes:3.0}, + 2: {name:"Aylin Duke",age:39,votingCard:[2,2],party:"Foam Party",numVotes:0.5}, + 3: {name:"Clay Roderick",age:54,votingCard:[3,4],party:"Flat Earth Party",numVotes:3.0}, + 4: {name:"Nour al-Din",age:32,votingCard:[4,1],party:"Pizza Party",numVotes:2.5} + }; + + expect(getWinner(candidatesAfterElection)).toEqual(null) +}) test('winnerMessage should return a message with the name of the winner and number of votes received', () => { const winner = { diff --git a/electionclass.js b/electionclass.js new file mode 100644 index 0000000..bed1df8 --- /dev/null +++ b/electionclass.js @@ -0,0 +1,20 @@ +class Election { + constructor(validVoters, candidates) { + this.validVoters = validVoters; + this.candidates = candidates; + this.winner = 'winner has not been chosen yet'; + } + runElection() { + this.candidates = runElection(this.validVoters, this.candidates) + + } getWinner() { + this.winner = getWinner(this.candidates); + + } printWinnerMessage() { + if (this.winner === null) { return "The election was a draw"; } + return this.winner.name + " has won the election with " + this.winner.numVotes + " votes!"; + } +} +module.exports = { + Election +} \ No newline at end of file diff --git a/electionclass.test.js b/electionclass.test.js new file mode 100644 index 0000000..12ffa94 --- /dev/null +++ b/electionclass.test.js @@ -0,0 +1,55 @@ +function runElection(validVoters, candidates) { + return candidates.map(item=>item.runElection()); //?map????? +} + +function getWinner(candidates) { + let winner = { numVotes: 0.0 }; + try { + Object.values(candidates).forEach(function (item) { + if (item.numVotes == winner.numVotes) { + throw "Duplicate"; + } + else if (item.numVotes > winner.numVotes) { + winner = item; + } + }) + } catch (error) { + return null; + } + return winner; +} +const { Election } = require("./electionclass.js") +test('running the election should add votes to the candidates', () => { + const validVoters = [ + {name: 'Jane Finnegan', age: 19, votingCard: [1,3]}, + {name: 'Norman Beracha', age: 35, votingCard: [3,4]}, + {name: 'Wei Li', age: 19, votingCard: [1,2]}, + {name: 'Sam MacKinnon', age: 59, votingCard: [1,4]}, + {name: 'Clay Roderick', age: 54, votingCard: [3,4], party: 'Flat Earth Party', numVotes: 0}, + {name: 'Nour al-Din', age: 32, votingCard: [4,1], party: 'Pizza Party', numVotes: 0} + ] + + expect(runElection(validVoters, candidates)).toEqual({ + 1: {name:"Tamara Faiza",age:46,votingCard:[1,1],party:"Pizza Party",numVotes:3.5}, + 2: {name:"Aylin Duke",age:39,votingCard:[2,2],party:"Foam Party",numVotes:0.5}, + 3: {name:"Clay Roderick",age:54,votingCard:[3,4],party:"Flat Earth Party",numVotes:2.5}, + 4: {name:"Nour al-Din",age:32,votingCard:[4,1],party:"Pizza Party",numVotes:2.5} + }) +}) + +test('getWinner should return the winning candidate', () => { + const candidatesAfterElection = { + 1: {name:"Tamara Faiza",age:46,votingCard:[1,1],party:"Pizza Party",numVotes:3.5}, + 2: {name:"Aylin Duke",age:39,votingCard:[2,2],party:"Foam Party",numVotes:0.5}, + 3: {name:"Clay Roderick",age:54,votingCard:[3,4],party:"Flat Earth Party",numVotes:2.5}, + 4: {name:"Nour al-Din",age:32,votingCard:[4,1],party:"Pizza Party",numVotes:2.5} + }; + + expect(getWinner(candidatesAfterElection)).toEqual({ + name: 'Tamara Faiza', + age: 46, + votingCard: [1, 1], + party: 'Pizza Party', + numVotes: 3.5, + }) +}) \ No newline at end of file diff --git a/index.html b/index.html index 90b9358..10ca65d 100644 --- a/index.html +++ b/index.html @@ -1,7 +1,38 @@ + - + - +

Welcome to Election Site

+
+
+

+ The list of Candidates +

+ +
+
+

The List of Voters

+ +
+ +
+
+ + + + \ No newline at end of file diff --git a/nefile b/nefile new file mode 100644 index 0000000..beb3be1 --- /dev/null +++ b/nefile @@ -0,0 +1,177 @@ +/* function candidatesObjToArray(candidates) { + var arrOfKeys = Object.keys(candidates); + var arrOfCandidates = arrOfKeys.map(function (key) { return candidates[key] }); + return arrOfCandidates; +} +/** + * 2 - Remove any voters who have voted for more than 2 people, or have voted for the same person twice. +*/ +function filterInvalidVoters(allVoters) { + const filteredByLength = allVoters.filter(item => item.votingCard.length < 3); + console.log('first filter', filteredByLength); + const filteredByClash = filteredByLength.filter(item => item.votingCard[0] !== item.votingCard[1]) + console.log('second filter',filteredByClash) + return filteredByClash; + } +/** + * 3 - Add up all the votes cast by the voting population. Note that for two adjacent votes in the vote array, + * the right vote counts for half of the left vote. + */ +//refactored Version of runElection +function runElection(validVoters, candidates) { + // console.log(validVoters, "validVoters") + //console.log(candidates,"candidates") + for (let i = 1; i <= Object.values(candidates).length; i++) { + //console.log("candidate", i) + validVoters.forEach(function (item) { + //console.log(item); + if (item.votingCard[0] === i) { + candidates[i].numVotes += 1 + } + if (item.votingCard[1] === i) + candidates[i].numVotes += 0.5; + }) + } + //console.log("after runElec",candidates) + return candidates; +} +/** + * 4 - After an election has been run, return the winner + * + * Desired return value: {name: "Tamara Faiza", age: 46, party: "Pizza Party", numVotes: 3} + */ +function getWinner(candidates) { + let winner = { numVotes: 0.0 }; + try { + Object.values(candidates).forEach(function (item) { + /* console.log(item.name,item.numVotes); + console.log(winner.name,winner.numVotes); + console.log(); */ + if (item.numVotes == winner.numVotes) { + throw "Duplicate"; + } + else if (item.numVotes > winner.numVotes) { + winner = item; + } + }) + } catch (error) { + return null; + } + return winner; +} +/** + * 5 - Return a message including the name of the winner, and how many votes + * he/she received + */ +function winnerMessage(winner) { + var winner = getWinner(candidates) + if (winner !== null) { + var mes = winner.name + " has won the election with " + winner.numVotes + " votes!"; + return mes; + } + else return "The election was a draw"; +} */ + +let urll = "https://www.mocky.io/v2/5a55224b2d000088425b1ed8" +// function sendRequest(url) { +// var xmlhttp = new XMLHttpRequest(); +// xmlhttp.onreadystatechange = function () { +// if (xmlhttp.readyState == 4 && xmlhttp.status == 200) { +// var data = JSON.parse(xmlhttp.responseText); +// console.log(data); +// } +// } +// xmlhttp.open("GET", url, true); +// xmlhttp.setRequestHeader("Access-Control-Allow-Origin","https://geojsonlint.com/") +// xmlhttp.send(); +// } +// sendRequest(urll) + +// console.log("hi") +// var ourReq=new XMLHttpRequest(); +// console.log("hi2") +// ourReq.open('GET','https://www.mocky.io/v2/5a55224b2d000088425b1ed8') +// ourReq.setRequestHeader("Access-Control-Allow-Origin","https://geojsonlint.com/") +// ourReq.onload=function(){ +// var ourData=JSON.parse(ourReq.responseText) +// console.log(ourData); +// console.log("hi3") +// }; +// ourReq.send(); +// console.log("hi4") + +//JSON works individually or even in a blank dev tools but doesent log when u open index.html, why ???? +// +///////////////////////////////////////////////////////////////////////////////////////////////////////////// + +function candidatesObjToArray(candidates) { + var arrOfKeys = Object.keys(candidates); + var arrOfCandidates = arrOfKeys.map(function (key) { return candidates[key] }); + return arrOfCandidates; +} +/** + * 2 - Remove any voters who have voted for more than 2 people, or have voted for the same person twice. +*/ +function filterInvalidVoters(allVoters) { + const filteredByLength = allVoters.filter(item => item.votingCard.length < 3); + const filteredByClash = filteredByLength.filter(item => item.votingCard[0] !== item.votingCard[1]) + return filteredByClash; +} +/** + * 3 - Add up all the votes cast by the voting population. Note that for two adjacent votes in the vote array, + * the right vote counts for half of the left vote. + */ +//refactored Version of runElection +function runElection(validVoters, candidates) { + // console.log(validVoters, "validVoters") + //console.log(candidates,"candidates") + for (let i = 1; i <= Object.values(candidates).length; i++) { + //console.log("candidate", i) + validVoters.forEach(function (item) { + //console.log(item); + if (item.votingCard[0] === i) { + candidates[i].numVotes += 1 + } + if (item.votingCard[1] === i) + candidates[i].numVotes += 0.5; + }) + } + //console.log("after runElec",candidates) + return candidates; +} +/** + * 4 - After an election has been run, return the winner + * + * Desired return value: {name: "Tamara Faiza", age: 46, party: "Pizza Party", numVotes: 3} + */ +function getWinner(candidates) { + let winner = { numVotes: 0.0 }; + try { + Object.values(candidates).forEach(function (item) { + /* console.log(item.name,item.numVotes); + console.log(winner.name,winner.numVotes); + console.log(); */ + if (item.numVotes == winner.numVotes) { + throw "Duplicate"; + } + else if (item.numVotes > winner.numVotes) { + winner = item; + } + }) + } catch (error) { + return null; + } + return winner; +} +/** + * 5 - Return a message including the name of the winner, and how many votes + * he/she received + */ +function winnerMessage(winner) { + var winner = getWinner(candidates) + if (winner !== null) { + var mes = winner.name + " has won the election with " + winner.numVotes + " votes!"; + return mes; + } + else return "The election was a draw"; +} \ No newline at end of file diff --git a/styles.css b/styles.css new file mode 100644 index 0000000..6aaad0d --- /dev/null +++ b/styles.css @@ -0,0 +1,66 @@ +body{ + width:70%; + margin:auto; + text-align: center; + background-image: url('https://tinyurl.com/ya3yy5q9'); + color:white; +} + +.container { + background-color: azure; + border:1px solid red; + min-height:400px; + height:auto !important; /* for IE as it does not support min-height */ + opacity: 0.5; + border-radius: 10px; + padding:5px; +} +ul,h3{ + color:black; + font-weight: bold; + text-align: left; +} +li{ + text-align: left; +} +.candidate-column, .voters-column { + width:45%; + margin:1%; + padding:1%; + float:left; + background-color:#f392b0; + border-radius: 10px; +} + +.container:after{ + content:""; + display:block; + clear:float; +} +button{ + color:red; + background-color: rgb(241, 8, 58); + border: none; + color: rgb(8, 8, 8); + padding: 15px 32px; + text-align: center; + text-decoration: none; + display: inline-block; + font-size: 16px; + margin: 4px 2px; + cursor: pointer; + font-weight: bold; + border-radius: 10px; +} +button:hover{ + background-color:yellow ; +} + +@media screen and (max-width: 600px) { + .voters-column , .candidate-column { + width: 90%; + } + .container{ + width:100%; + } +} \ No newline at end of file diff --git a/voter.js b/voter.js new file mode 100644 index 0000000..0b54457 --- /dev/null +++ b/voter.js @@ -0,0 +1,14 @@ +class Voter { + constructor(name, age, votingCard) { + + this.name = name; + this.age = age; + this.votingCard = votingCard; + } + valid() { + return this.votingCard.length < 3 && this.votingCard[0] !== this.votingCard[1] + } +} +module.exports = { + Voter +} \ No newline at end of file diff --git a/voter.test.js b/voter.test.js new file mode 100644 index 0000000..47c5b10 --- /dev/null +++ b/voter.test.js @@ -0,0 +1,35 @@ +function filterInvalidVoters(allVoters) { + return allVoters.filter(item => item.valid()) +} +const { Voter } = require("./voter") +test("return only valid voters",()=> { + let votingPopulation = [ + new Voter('Jane Finnegan', 19, [1, 3]), + new Voter('Norman Beracha', 35, [3, 4]), + new Voter('Salome Kadek', 22, [2, 1, 3]), + new Voter('Wei Li', 19, [1, 2]), + new Voter('Sam MacKinnon', 59, [1, 4]) + ] + expect(filterInvalidVoters(votingPopulation)).toEqual([ + new Voter('Jane Finnegan', 19, [1, 3]), + new Voter('Norman Beracha', 35, [3, 4]), + new Voter('Wei Li', 19, [1, 2]), + new Voter('Sam MacKinnon', 59, [1, 4])] + ) +} +) +test('if it has a name', () => { + let voter = new Voter("mahsa", "18", [1, 2, 3]); + expect(voter.name).toEqual( + "mahsa" + ) +}) + +test("if the voting card is valid",()=>{ + let voter=new Voter("mahsa", "18", [1, 2]); + expect(voter.valid()).toEqual(true); +}) +test("if the voting card is invalid",()=>{ + let voter=new Voter("mahsa", "18", [1, 2,3]); + expect(voter.valid()).toEqual(false); +}) \ No newline at end of file