First refer to the Qunit Test framework file
<link rel= "stylesheet" href= "Qunit-1.22.0.css" >
<script src= "Qunit-1.22.0.js" ></script>
<div id= "Qunit" ></div>
<div id= "Qunit-fixture" ></div>
<script>
function Triangle (A, B, c) {
if (a && b && c && a > 0 && B > 0 && C > 0 && a < (b + c) & ;& B < (a + c) && C < (A + b)) {
if (! ( This instanceof Triangle)) {
return new Triangle (A, B, c);
}
THIS.A = A;
this.b = b;
THIS.C = C;
This.s=function () {
var p = (THIS.A+THIS.B+THIS.C)/2;
Return Math.sqrt (p* (P-THIS.A) * (p-this.b) * (P-THIS.C));
}
return true;
}
return false;
}
Triangle.prototype.zj=function () {
Return!! ((THIS.A==THIS.B&&THIS.A!=THIS.C) | | (this.a==this.c&&this.a!=this.b))
}
Triangle.prototype.qd=function () {
Return!! (THIS.A==THIS.B&&THIS.A==THIS.C)
}
Qunit.test ("Test is a triangle", function (assert) {
Assert.equal (MATH.SQRT (8) *math.sqrt (8), 8, "math.sqrt (8)");
Assert.equal (Math.ceil (Triangle (MATH.SQRT (8), 2,2). S ()), 2, "Area 2");
Assert.ok (Triangle ("1", 1, 1), "is a triangle");
Assert.ok (Triangle (MATH.SQRT (8), 2,2), "is a triangle");
});
Qunit.test ("Test triangle Type", function (assert) {
Assert.ok ("1", "Triangle"). ZJ (), "right triangle");
Assert.ok ("1", "Triangle"). QD (), "congruent triangle");
Assert.ok (Triangle (MATH.SQRT (8), 2,2). ZJ (), "right triangle");
Assert.ok (Triangle (MATH.SQRT (8), 2,2). QD (), "congruent triangles");
});
</script>
This is a test case for judging the type of triangle, the following is the result of the operation:
Qunit Front-end script test Cases