From 617fb2d36f6cda0fc20da65518c6d6d9b04794e7 Mon Sep 17 00:00:00 2001 From: Lev Date: Mon, 17 May 2021 00:14:14 -0500 Subject: [PATCH] Add Initial commit --- .../Topic 2/5.1.6/testme.js | 48 +++++++++++++++++++ 1 file changed, 48 insertions(+) create mode 100644 CM2010 Software Design and Development/Topic 2/5.1.6/testme.js diff --git a/CM2010 Software Design and Development/Topic 2/5.1.6/testme.js b/CM2010 Software Design and Development/Topic 2/5.1.6/testme.js new file mode 100644 index 0000000..2509abc --- /dev/null +++ b/CM2010 Software Design and Development/Topic 2/5.1.6/testme.js @@ -0,0 +1,48 @@ +function getHighest(input) +{ + let max = input.length - 1; + + for(let i = 0; i < input.length; i++) + if(input[i] > max) max = input[i]; + return max; +} + +function testCorrectRes() +{ + let input = [1, 2, 4, 5, 6]; + let res = getHighest(input); + + let max = Math.max.apply(null, input); + if(res == max) return true; + else return false; +} + +function testResInArray() +{ + let input = [1, 2, 4, 5, 6]; + let res = getHighest(input); + + if(input.includes(res)) return true; + else return false; +} + +function testRetVal() +{ + let input = [1, 2, 4, 5, 6]; + let res = getHighest(input); + + if(res == undefined) return false; + else return true; +} + +let res = testRetVal(); +if(res) console.log('testRetVal passed'); +else console.log('testRetVal failed'); + +res = testResInArray(); +if(res) console.log('testResInArray passed'); +else console.log('testResInArray failed'); + +res = testCorrectRes(); +if(res) console.log('testCorrectRes passed'); +else console.log('testCorrectRes failed'); \ No newline at end of file