⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 regress.cal

📁 Calc Software Package for Number Calc
💻 CAL
📖 第 1 页 / 共 5 页
字号:
/* * regress - calc regression and correctness test suite * * Copyright (C) 1999-2006  David I. Bell and Landon Curt Noll * * Calc is open software; you can redistribute it and/or modify it under * the terms of the version 2.1 of the GNU Lesser General Public License * as published by the Free Software Foundation. * * Calc is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY * or FITNESS FOR A PARTICULAR PURPOSE.	 See the GNU Lesser General * Public License for more details. * * A copy of version 2.1 of the GNU Lesser General Public License is * distributed with calc under the filename COPYING-LGPL.  You should have * received a copy with calc; if not, write to Free Software Foundation, Inc. * 59 Temple Place, Suite 330, Boston, MA  02111-1307, USA. * * @(#) $Revision: 29.36 $ * @(#) $Id: regress.cal,v 29.36 2006/12/16 11:18:46 chongo Exp $ * @(#) $Source: /usr/local/src/cmd/calc/cal/RCS/regress.cal,v $ * * Under source code control:	1990/02/15 01:50:36 * File existed as early as:	before 1990 * * Share and enjoy!  :-)	http://www.isthe.com/chongo/tech/comp/calc/ *//* * Test the correct execution of the calculator by reading this resource file. * Errors are reported with '****' messages, or worse.	:-) * * NOTE: Unlike most calc resource files, this one performs its work when *	 it is read.  Normally one would just define functions and *	 values for later use.	In the case of the regression test, *	 we do not want to do this. */print '000: Beginning regression tests';print '001: Some of these tests may take a while ...';print '002: Within each section, output should be numbered sequentially';global prob;				/* libregress.cal problem counter */prob = 0;				/* clear problem counter */errcount(0),;				/* clear error count */errmax(-1),;				/* prevent errcount from abouting */global ecnt;				/* expected value of errcount() */ecnt = 0;				/* clear expected errcount() value */initcfg = config("all", "newstd");	/* set config to startup default */defcfg = config("all");			/* capture the default config */config("resource_debug", 0),;		/* disable resource startup messages */config("calc_debug", 0),;		/* disable internal debugging */config("verbose_quit", 0),;		/* disable quit messages */startcfg = config("all");		/* save state for later use */print '003: parsed global definitions';/* * vrfy - vrfy that a test is true * * Counts and reports errors or prints test string if successful. * * This function also detects when errcount() exceeds ecnt * and reports when this happens.  A side effect is that a * new ecnt level is established.  If errcount exceeds errcount * but otherwise the test is successful, the string is still printed. */define vrfy(test, str){	if (errcount() > ecnt) {		print '**** errcount:' : errcount(), ' > ecnt:' : ecnt;		ecnt = errcount();		++prob;	}	if (test != 1) {		print '**** Non-true result (' : test : '): ' : str;		++prob;	} else {		print str;	}	return;}print '004: parsed vrfy()';/* * prob - alternate error notification and count */define prob(str){	print '****' , str;	++prob;}print '005: parsed prob(str)';/* * getglobalvar - used to return a global value */define getglobalvar(){	global	globalvar;	return globalvar;}print '006: parsed getglobalvar()';/* * Test boolean operations and IF tests. * * Some of these tests are done twice, once to print the message and * once to count any errors.  This means that some successful tests * will display a passing message twice.  Oh well, no biggie. */define test_booleans(){	local	x;	local	y;	local	t1, t2, t3;	print '300: Beginning test_booleans';	if (0)		print '**** if (0)';	if (0)		prob = prob + 1;	if (1)		print '301: if (1)';	if (2)		print '302: if (2)';	if (1)		print '303: if (1) else';	else		print '**** if (1) else';	if (1)		print '304: if (1) else';	else		prob = prob + 1;	if (0)		print '**** if (0) else';	else		print '305: if (0) else';	if (0)		prob = prob + 1;	else		print '306: if (0) else';	if (1 == 1)		print '307: if 1 == 1';	else		print '**** if 1 == 1';	if (1 == 1)		print '308: if 1 == 1';	else		prob = prob + 1;	if (1 != 2)		print '309: if 1 != 2';	else		print '**** if 1 != 2';	if (1 != 2)		print '310: if 1 != 2';	else		prob = prob + 1;	vrfy(1,	     '311: vrfy 1');	vrfy(2 == 2, '312: vrfy 2 == 2');	vrfy(2 != 3, '313: vrfy 2 != 3');	vrfy(2 <  3, '314: vrfy 2 <  3');	vrfy(2 <= 2, '315: vrfy 2 <= 2');	vrfy(2 <= 3, '316: vrfy 2 <= 3');	vrfy(3 >  2, '317: vrfy 3 >  2');	vrfy(2 >= 2, '318: vrfy 2 >= 2');	vrfy(3 >= 2, '319: vrfy 3 >= 2');	vrfy(!0,     '320: vrfy !0');	vrfy(!1 == 0,'321: vrfy !1 == 0');	vrfy((1 ? 2 ? 3 : 4 : 5) == 3,	  '322: (1 ? 2 ? 3 : 4 : 5) == 3');	print '323: Ending test_booleans';}print '007: parsed test_booleans()';/* * Test variables, simple assignments, AND and OR operators, short-circuit eval */define test_variables(){	local	x1, x2, x3;	global	g1, g2;	local	t;	local x;	print '350: Beginning test_variables';	x1 = 5;	x3 = 7 * 2;	x2 = 9 + 1;	globalvar = 22;	g1 = 19 - 3;	g2 = 79;	vrfy(x1 == 5,			'351: x1 == 5');	vrfy(x2 == 10,			'352: x2 == 10');	vrfy(x3 == 14,			'353: x3 == 14');	vrfy(g1 == 16,			'354: g1 == 16');	vrfy(g2 == 79,			'355: g2 == 79');	vrfy(globalvar == 22,		'356: globalvar == 22');	vrfy(getglobalvar() == 22,	'357: getglobalvar() == 22');	x1 = x2 + x3 + g1;	vrfy(x1 == 40,			'358: x1 == 40');	g1 = x3 + g2;	vrfy(g1 == 93,			'359: g1 == 207');	x1 = 5;	vrfy(x1++ == 5,			'360: x1++ == 5');	vrfy(x1 == 6,			'361: x1 == 6');	vrfy(++x1 == 7,			'362: ++x1 == 7');	x1 += 3;	vrfy(x1 == 10,			'363: x1 == 10');	x1 -= 6;	vrfy(x1 == 4,			'364: x1 == 4');	x1 *= 3;	vrfy(x1 == 12,			'365: x1 == 12');	x1 /= 4;	vrfy(x1 == 3,			'366: x1 == 3');	x1 = x2 = x3;	vrfy(x2 == 14,			'367: x2 == 14');	vrfy(x1 == 14,			'368: x1 == 14');	if (2 && 3) {		print '369: if (2 && 3)';	} else {		print '**** if (2 && 3)';		++prob;	}	if (2 && 0) {		print '**** if (2 && 0)';		++prob;	} else {		print '370: if (2 && 0)';	}	if (0 && 2) {		print '**** if (0 && 2)';		++prob;	} else {		print '371: if (0 && 2)';	}	if (0 && 0) {		print '**** if (0 && 0)';		++prob;	} else {		print '372: if (0 && 0)';	}	if (2 || 0) {		print '373: if (2 || 0)';	} else {		print '**** if (2 || 0)';		++prob;	}	if (0 || 2) {		print '374: if (0 || 2)';	} else {		print '**** if (0 || 2)';		++prob;	}	if (0 || 0) {		print '**** if (0 || 0)';		++prob;	} else {		print '375: if (0 || 0)';	}	x = 2 || 3; vrfy(x == 2,	'376: (2 || 3) == 2');	x = 2 || 0; vrfy(x == 2,	'377: (2 || 0) == 2');	x = 0 || 3; vrfy(x == 3,	'378: (0 || 3) == 3');	x = 0 || 0; vrfy(x == 0,	'379: (0 || 0) == 0');	x = 2 && 3; vrfy(x == 3,	'380: (2 && 3) == 3');	x = 2 && 0; vrfy(x == 0,	'381: (2 && 0) == 0');	x = 0 && 3; vrfy(x == 0,	'382: (0 && 3) == 0');	x = 2 || prob('2 || prob()');	print				"383: x = 2 || prob('2 || prob()'";	x = 0 && prob('0 && prob()');	print				"384: x = 0 && prob('0 && prob()'";	print				'385: Ending test_variables';}print '008: parsed test_variables()';/* * Test simple arithmetic operations and expressions. */define test_arithmetic(){	print '400: Beginning test_arithmetic';	vrfy(3+4==7,		'401: 3 + 4 == 7');	vrfy(4-1==3,		'402: 4 - 1 == 3');	vrfy(2*3==6,		'403: 2 * 3 == 6');	vrfy(8/4==2,		'404: 8 / 4 == 2');	vrfy(2^3==8,		'405: 2 ^ 3 == 8');	vrfy(9-4-2==3,		'406: 9-4-2 == 3');	vrfy(9-4+2==7,		'407: 9-4+2 == 7');	vrfy(-5+2==-3,		'408: -5+2 == -3');	vrfy(2*3+1==7,		'409: 2*3+1 == 7');	vrfy(1+2*3==7,		'410: 1+2*3 == 7');	vrfy((1+2)*3==9,	'411: (1+2)*3 == 9');	vrfy(2*(3+1)==8,	'412: 2*(3+1) == 8');	vrfy(9-(2+3)==4,	'413: 9-(2+3) == 4');	vrfy(9+(2-3)==8,	'414: 9+(2-3) == 8');	vrfy((2+3)*(4+5)==45,	'415: (2+3)*(4+5) == 45');	vrfy(10/(2+3)==2,	'416: 10/(2+3) == 2');	vrfy(12/3+4==8,		'417: 12/3+4 == 8');	vrfy(6+12/3==10,	'418: 6+12/3 == 10');	vrfy(2+3==1+4,		'419: 2+3 == 1+4');	vrfy(-(2+3)==-5,	'420: -(2+3) == -5');	vrfy(7&18==2,		'421: 7&18 == 2');	vrfy(3|17==19,		'422: 3|17 == 19');	vrfy(2&3|1==3,		'423: 2&3|1 == 3');	vrfy(2&(3|1)==2,	'424: 2&(3|1) == 2');	vrfy(3<<4==48,		'425: 3<<4 == 48');	vrfy(5>>1==2,		'426: 5>>1 == 2');	vrfy(3<<-1==1,		'427: 3<<-1 == 1');	vrfy(5>>-2==20,		'428: 5>>-2 == 20');	vrfy(1<<2<<3==65536,	'429: 1<<2<<3 == 65536');	vrfy((1<<2)<<3==32,	'430: (1<<2)<<3 == 32');	vrfy(2^3^2==512,	'431: 2^3^2 == 512');	vrfy((2^3)^2==64,	'432: (2^3)^2 == 64');	vrfy(4//3==1,		'433: 4//3==1');	vrfy(4//-3==-1,		'434: 4//-3==-1');	vrfy(0.75//-0.51==-1,	'435: 0.75//-0.51==-1');	vrfy(0.75//-0.50==-1,	'436: 0.75//-0.50==-1');	vrfy(0.75//-0.49==-1,	'437: 0.75//-0.49==-1');	vrfy((3/4)//(-1/4)==-3, '438: (3/4)//(-1/4)==-3');	vrfy(7%3==1,		'439: 7%3==1');	vrfy(0-.5==-.5,		'440: 0-.5==-.5');	vrfy(0^0 == 1,		'441: 0^0 == 1');	vrfy(0^1 == 0,		'442: 0^1 == 0');	vrfy(1^0 == 1,		'443: 1^0 == 1');	vrfy(1^1 == 1,		'444: 1^1 == 1');	vrfy(1/(.8+.8i)==.625-.625i,	'445: 1/(.8+.8i)==.625-.625i');	vrfy((.6+.8i)*(3.6-4.8i)==6,	'446: (.6+.8i)*(3.6-4.8i)==6');	vrfy(-16^-2 == -1/256,	'447: -16^-2 == -1/256');	vrfy(-7^2 == -49,	'448: -7^2 == -49');	vrfy(-3! == -6,		'449: -3! == -6');	print '450: Ending test_arithmetic';}print '009: parsed test_arithmetic()';

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -