Artifact [4daac9ff13]
Not logged in

Artifact 4daac9ff13331ef234596e15f091d4b39e99d5ff:



<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.");







window.onload = function(){

	var canvas = document.createElement("canvas");
	
	canvas.width = 500;
	canvas.height = 500;
	
	document.body.appendChild(canvas);
	
	var ctx = canvas.getContext("2d");
	
	
	var model = new WireframeModel();
	model.addPoint([0, 0, 0]);
	model.addPoint([0, .1, 0]);
	model.addPoint([0, 0, .1]);
	model.addPoint([-.1, .1, 0]);
	model.addPoint([-.1, 0, .1]);
	
	model.draw(canvas);


}


</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>