Qunit tests

by Максим Булавинов

HTML

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" 
                    "http://www.w3.org/TR/html4/loose.dtd">
<html>
    <head>
        <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/qunit/2.12.0/qunit.css" integrity="sha512-WHHHtr+PajsUg/2hzN06oiDErAyCDDUnv5mGTL/stZEpnCSk7jyh5/Um1KX/5+r2mYqp6UQrYEK8QSVQUhCHpQ==" crossorigin="anonymous" />
    </head>
    <body>
        <h1 id="qunit-header">QUnit example</h1>
        <h2 id="qunit-banner"></h2>
        <div id="qunit-testrunner-toolbar"></div>
        <h2 id="qunit-userAgent"></h2>
        <ol id="qunit-tests"></ol>
        <div id="qunit-fixture">test markup, will be hidden</div>
        <script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/qunit/2.12.0/qunit.js"></script>  
    </body>
</html>

JavaScript

$(function () {
    var Obj = function( val ){
            this.value = val;
    };
    Obj.prototype.toString = function(){
        return this.value;
    };
    Obj.prototype.valueOf = function(){
        return this.value;
    };
    var x = new Obj(42);
    var y = new Obj(42);
    var z = new Obj(10);
    QUnit.test("Comparing custom objects", function (assert) {
        assert.equal(x >= y, true, "x >= y");
        assert.equal(x <= y, true, "x <= y");
        assert.equal(x >= z, true, "x >= z");
        assert.equal(y >= z, true, "y >= z");
        assert.equal(x.toString(), y.toString(), "toString equals");
        assert.equal(+x == +y, true, "(+x == +y) => true");
        assert.equal(x == y, false, "(x == y) => false");
				assert.equal(!(x - y), true, "!(x - y) => true");
				assert.equal(!(z - x), false, "!(z - x) => false");
    });
});