Artifact [d11af1c4b7]
Not logged in

Artifact d11af1c4b75146c85afa45382d77496599ede851:



<html>
<head>

<script src="wireframe_model.js"></script>



<script>

////
//  Some helper stuff for running tests.
////


var testcount = 0;

function mustThrowError(func, testname){
	++testcount;
	if(!testname) testname = "Test_" + testcount;
	var threwsomething = false;
	try{ func(); }
	catch(excpt){ threwsomething = true; }
	if(!threwsomething)
		throw "'" + testname + "' did not throw an error, it was supposed to throw an error!";
}

function mustNotThrowError(func, testname){
	++testcount;
	if(!testname) testname = "Test_" + testcount;
	try{ func(); }
	catch(excpt){
		throw "'" + testname + "' failed and threw an error: " + excpt; }}
		

function assert(value, testname){
	++testcount;
	if(!testname) testname = "Test_" + testcount;
	
	if(!value) throw "Assertion " + testname + " failed"; }
	
	
	
////
//
//  WireframeModel test cases.
//
//  You should play around with these to convince yourself that they work the way they are supposed to.
//
////
	
	
var model = new WireframeModel();

mustThrowError(function(){ model.addPoint("hippo"); }, "addpoint hippo");
mustThrowError(function(){ model.addPoint([1, 2, 3, 0]); }, "addpoint too long");
mustThrowError(function(){ model.addPoint(7); });
mustThrowError(function(){ model.addPoint([1, 2, "a"]); });

assert(0 == model.addPoint([1.3845, -0.110, 7]));
assert(1 == model.addPoint([1.3845, -0.110, -7]));

mustThrowError(function(){ model.addLine("dolphin"); }, "addline dolphin");
mustThrowError(function(){ model.addLine([1]); }, "addline too short");
mustThrowError(function(){ model.addLine([-1, 0]); }, "addline out of bounds negative");
mustThrowError(function(){ model.addLine([0, 7]); }, "addline out of bounds");

assert(0 == model.addLine([0, 1]));
assert(1 == model.addLine([1, model.addPoint([-1.3845, -0.110, 7])]));





alert("Tests completed.");

// uncomment when you want to prove must throw error actually does something
// mustThrowError(function(){ }, "check mustthrowerror works. have it do nothing.");






</script>


</head>

<body>
<p>
This is a test page that encapsulates scripts for testing wireframe_model.js
</p>
<p>
If tests are successful, a message will say so and no errors will be thrown.
</p>
</body>

</html>