%Lecture 11 - Testing

%Motivating example:

%Write a program to get an employee ID and a password from a user. 
% First, the program should repeatedly prompt the user for an ID until the
%  user enters a valid ID.
% Then the program should repeatedly prompt the user for a password until
%  the user enters a valid password. 
%
%An ID is valid if it is a 7 digit number (and the first digit can't be 0).
%A password is valid if it meets the following two criteria:
%1.	it is at least 6 but no more than 10 character long
%2.	the first character is a letter or an underscore

%Input ID
done = 0;
id = input('Enter your employee ID: ');
while ~done
  if length(id) ~= 1
    id = input('Vector input not supported. Enter your ID: ');
  elseif ~isnumeric(id)
    id = input('ID is not a numeric value. Enter your ID: ');
  elseif id < 1000000 || id > 9999999
		id = input('Invalid ID. Enter your ID: ');
  elseif mod(id,1) ~= 0
    id = input('Floating point numbers are not allowed. Enter your ID: ');
	else
		done = 1;
	end
end

%Input Password
done = 0;
while ~done
	passwd = input('Enter your password: ', 's');
	if length(passwd) < 6 || length(passwd) > 10
		disp('invalid – bad length')
	elseif ~(isletter(passwd(1)) || passwd(1) == '_')
    disp('invalid – must start with letter or _')
	else
		done = 1;
	end
end

%How do I want to test this code?
%Build a set of tests that cover each piece of code
%A set of tests is often a called a test suite
%The goal of a test suite is to ensure that each line
%of code is tested at least once by the test suite

%Test coverage: Test all kinds of cases, both good and bad
%Positive test cases - "Good input", intended execution
%Negative test cases - "Bad input", unintended input
%Corner test cases - edge cases between good and bad test cases

%Test cases used above:
%1234567 - good test cases, worked as intended
%123abc - bad test case, caused an error
%No input - bad test case, caused an error
%1234567.8 - bad test case, didn't cause an error, but allowed an invalid
%ID through
%Vector of numbers - bad test case, caused an error
%String (or character) - bad test case, caused an error for a string,
%repromted user for a character

%How can we fix these?
%123abc - this error was caused by an invalid input to input, not really in
%our control, ignore this for now
%No input - this was caused by a 0x0 matrix. Can check the length of id
%1234567.8 - recall mod function. test mod(id,1) == 0, true if id is an
%integer, false otherwise
%Vector of numbers - Again can check the length of id
%String (or character) - String is handled by the length check. Can check
%if the value is not a numeric value by using isnumeric
