From 4bd83be537b7673ac043616d002a715a67cb4998 Mon Sep 17 00:00:00 2001 From: Lance Lafontaine Date: Thu, 14 Apr 2016 23:42:08 -0400 Subject: [PATCH] Adds tests to repository --- test/loginUnitTests.js | 85 +++++++++++++++++++++++++++++ test/scheduleUnitTests.js | 110 ++++++++++++++++++++++++++++++++++++++ test/stressTesting.py | 28 ++++++++++ 3 files changed, 223 insertions(+) create mode 100644 test/loginUnitTests.js create mode 100644 test/scheduleUnitTests.js create mode 100644 test/stressTesting.py diff --git a/test/loginUnitTests.js b/test/loginUnitTests.js new file mode 100644 index 0000000..1cfd7c6 --- /dev/null +++ b/test/loginUnitTests.js @@ -0,0 +1,85 @@ +var log = require('../models/login'); + +// Test Case #1 - Valid Username and Valid Password +var username1 = "super_veko@yahoo.com"; +var password1 = "soen341"; +var testLogin = function(login, username, password) { + if (login(username, password) != undefined) { + console.log('Test Case #1 Passed!'); + } else { + console.log('Test Case #1 Failed!'); + } +} +testLogin(log.login, username1, password1); +log.logout(); //Making sure it's logged out before next test + +// Test Case #2 - Invalid Username and Valid Password +var username2 = "super_beko@yahoo.com"; +var password2 = "soen341"; +var testLogin = function(login, username, password) { + if (login(username, password) != undefined) { + console.log('Test Case #2 Passed!'); + } else { + console.log('Test Case #2 Failed!'); + } +} +testLogin(log.login, username2, password2); +log.logout(); //Making sure it's logged out before next test + + + + +// Test Case #3 - Valid Username and Invalid Password +var username3 = "super_veko@yahoo.com"; +var password3 = "inconnectpassword"; +var testLogin = function(login, username, password) { + if (login(username, password) != undefined) { + console.log('Test Case #2 Passed!'); + } else { + console.log('Test Case #2 Failed!'); + } +} +testLogin(log.login, username3, password3); +log.logout(); //Making sure it's logged out before next test + +// EXPECTED OUTPUT +// Test Case #1 Passed! +// Test Case #2 Failed! +// Test Case #3 Failed! + +// Test Case #4 - User is logged in, tries logout +var username4 = "super_veko@yahoo.com"; +var password4 = "soen341"; +log.login(username4, password4); //Login correctly first +var testLogout = function(logout) { + if (logout() != undefined) { + console.log('Test Case #4 Passed!'); + } else { + console.log('Test Case #4 Failed!') + } +} +testLogout(log.logout); + +// Test Case #5 - User that is NOT logged in, tries to logout +var testLogout = function(logout) { + if (logout() != undefined) { + console.log('Test Case #5 Passed!'); + } else { + console.log('Test Case #5 Failed!') + } +} +testLogout(log.logout); + +// Test Case #6 - User is logged in, test to check whether he is logged in or not +var username6 = "super_veko@yahoo.com"; +var password6 = "soen341"; +log.login(username6, password6); +var testIsLoggedIn = function(isLoggedIn) { + if (isLoggedIn() != undefined) { + console.log('Test Case #6 Passed!'); + } else { + console.log('Test Case #6 Failed!') + } +} +testIsLoggedIn(log.isLoggedIn); +log.logout(); //Making sure it's logged out before next test \ No newline at end of file diff --git a/test/scheduleUnitTests.js b/test/scheduleUnitTests.js new file mode 100644 index 0000000..b799400 --- /dev/null +++ b/test/scheduleUnitTests.js @@ -0,0 +1,110 @@ +var _ = require('underscore'); +var course = require('../models/course'); + +// Test Case #1 - course has one sections +var courseWithOneSection = Object.create(course.id = 'SOEN492'); +var testGetAssociatedSections = function(getAssociatedSections) { + if (getAssociatedSections() !== undefined && + getAssociatedSections().length === 1 && + typeof getAssociatedSections() === section) { + console.log('Test Case #1 Passed!'); + } else { + console.log('Test Case #1 Failed!'); + } +}; +testGetAssociatedSections(courseWithOneSection.getAssociatedSections); + + +// Test Case #2 - course has multiple sections +var courseWithMultipleSections = Object.create(course.id = 'SOEN341'); +var testCourseWithMultipleSections = function(getAssociatedSections) { + if (getAssociatedSections() !== undefined && + getAssociatedSections().length > 1 && + getAssociatedSections().map(function(i) { + return typeof i === section + })) { + console.log('Test Case #2 Passed!'); + } else { + console.log('Test Case #2 Failed!'); + } +}; +testGetAssociatedSections(courseWithMultipleSections.getAssociatedSections); + +// Test Case #3 - course has no sections +var courseWithNoSections = Object.create(course.id = 'SOEN3074'); +var testCourseWithNoSections = function(getAssociatedSections) { + if (getAssociatedSections() !== undefined && + getAssociatedSections().length >= 1 && + getAssociatedSections().map(function(i) { + return typeof i === section + })) { + console.log('Test Case #3 Passed!'); + } else { + console.log('Test Case #3 Failed!'); + } +} +testCourseWithNoSections(courseWithNoSections.getAssociatedSections); + +// EXPECTED OUTPUT +// Test Case #1 Passed! +// Test Case #2 Passed! +// Test Case #3 Failed! + +// Test Case #4 - All Sections exists +var allSectionsExist = Object.create(course.id = 'SOEN341'); +var testListSectionTimes = function(course) { + if (course.listSectionTimes(course.getAssociatedSections) !== undefined && + course.listSectionTimes(course.getAssociatedSections).length > 0 && + _.isEqual(course.listSectionTimes(course.getAssociatedSections), ['H HA', 'H HB'])) { + console.log('Test Case #4 Passed!'); + } else { + console.log('Test Case #4 Failed!'); + } +} +testAllSectionsExist(allSectionsExist); + +// Test Case #5 - At least one section doesn't exist +var sectionDoesntExist = Object.create(course.id = 'SOEN341'); +var testSectionDoesntExist = function(course) { + if (course.listSectionTimes(course.getAssociatedSections) !== undefined && + course.listSectionTimes(course.getAssociatedSections).length > 0 && + _.isEqual(course.listSectionTimes(course.getAssociatedSections), ['H HA', 'H HB'])) { + console.log('Test Case #5 Passed!'); + } else { + console.log('Test Case #5 Failed!'); + } +} +testSectionDoesntExist(sectionDoesntExist); + +// EXPECTED OUTPUT +// Test Case #4 Passed! +// Test Case #5 Failed! + +// Test Case #6 - Course has correct credits +var realCourse = Object.create(course.id = 'SOEN341'); +var testCourseCredits = function(courseCredits) { + if (courseCredits() !== undefined && + typeOf courseCredits() === "number" && + courseCredits() === 3) { + console.log('Test Case #6 Passed!'); + } else { + console.log('Test Case #6 Failed!'); + } +}; +testCourseCredits(realCourse.courseCredits); + +// Test Case #7 - Non-existant course does not have credits +var fakeCourse = Object.create(course.id = 'SOEN3411w3r'); +var testCourseCredits = function(courseCredits) { + if (courseCredits() !== undefined && + typeOf courseCredits() === "number") { + console.log('Test Case #7 Passed!'); + } else { + console.log('Test Case #7 Failed!'); + } +}; +testCourseCredits(fakeCourse.courseCredits); + +// EXPECTED OUTPUT +// Test Case #6 Passed! +// Test Case #7 Failed! \ No newline at end of file diff --git a/test/stressTesting.py b/test/stressTesting.py new file mode 100644 index 0000000..f73aed3 --- /dev/null +++ b/test/stressTesting.py @@ -0,0 +1,28 @@ +import urllib.request +import time + +numOfRequests = 10000 + +def makeRequests(numOfRequests): + for index in range(numOfRequests): + f = urllib.request.urlopen('http://159.203.40.62:3000') + if index == 0: + initialCode = f.getcode() + if index == numOfRequests - 1: + endCode = f.getcode() + index += 1 + return [initialCode, endCode] + +print('Stress testing web application. Please wait...') +startTime = time.time() +results = makeRequests(numOfRequests); +elapsedTime = time.time() - startTime + +requestsPerSecond = numOfRequests / elapsedTime +systemIsUp = results[0] == results[1] + +print('---') +print('Numer of requests: ' + str(numOfRequests)) +print('Number of seconds: ' + str(elapsedTime)) +print('Number of requests per second: ' + str(requestsPerSecond)) +print('System is still operational: '+ str(systemIsUp))