function [score, time] = harness2(n,niters,whichstart) % HARNESS2 : Test and validation harness for homework 2 % % [score, time] = harness2(n,niters,whichstart); % % This generates an n-by-n array (default n=100), % runs an external "life" routine to play the game % of life on it for "niters" iterations (default niters=5*n), % and reports timing and correctness. % "whichstart" (default 1) is an integer specifying % which of several starting positions to use. % % John R. Gilbert 26 Jan 2006 if nargin < 1 n = 100; end; if nargin < 2 niters = 5*n; end; if nargin < 3 whichstart = 1; end; fprintf('Matlab test harness for CS240A Homework 2.\n'); fprintf('Number of processors = 1 (sequential Matlab code)\n'); fprintf('Array dimension = %d\n', n); fprintf('Number of generations = %d\n', niters); A = gendata2(n, whichstart); tic; livecounts = life(A, niters); time = toc; fprintf('Elapsed time = %d\n', time); fprintf('Final number of live cells = %d\n', livecounts(end)); score = validate2(n, whichstart, niters, livecounts); if score == 1 fprintf('Answer is correct.\n'); elseif score == 0 fprintf('Answer is not correct.\n'); end;