Commit 2a233ada authored by 0mkar's avatar 0mkar

add number weight tests

parent c7d02259
...@@ -97,5 +97,45 @@ library Assert { ...@@ -97,5 +97,45 @@ library Assert {
AssertionEvent(result, message); AssertionEvent(result, message);
} }
/*----------------- Greater than --------------------*/
function greaterThan(uint a, uint b, string message) public constant returns (bool result) {
result = (a > b);
emit AssertionEvent(result, message);
}
function greaterThan(int a, int b, string message) public constant returns (bool result) {
result = (a > b);
emit AssertionEvent(result, message);
}
// TODO: safely compare between uint and int
function greaterThan(uint a, int b, string message) public constant returns (bool result) {
if(b < int(0)) {
// int is negative a always greater
result = true;
} else {
result = (a > uint(b));
}
emit AssertionEvent(result, message);
}
function greaterThan(int a, uint b, string message) public constant returns (bool result) {
if(a < int(0)) {
// int is negative a always greater
result = false;
} else {
result = (uint(a) > b);
}
emit AssertionEvent(result, message);
}
/*----------------- Lesser than --------------------*/
function lesserThan(uint a, uint b, string message) public constant returns (bool result) {
result = (a < b);
emit AssertionEvent(result, message);
}
function lesserThan(int a, int b, string message) public constant returns (bool result) {
result = (a < b);
emit AssertionEvent(result, message);
}
// TODO: safely compare between uint and int
} }
` `
pragma solidity ^0.4.24;
contract IntegerTest {
function _2_shouldBeGreaterThan_1() public constant returns (bool) {
return Assert.greaterThan(uint(2), uint(1), "2 is not greater than 1");
}
function _2_shouldBeGreaterThan_neg_1() public constant returns (bool) {
return Assert.greaterThan(uint(2), int(-1), "2 is not greater than -1");
}
function _neg_1_shouldNotBeGreaterThan_2() public constant returns (bool) {
return Assert.greaterThan(int(-1), uint(2), "-1 is not greater than 2");
}
}
...@@ -95,8 +95,8 @@ describe('testRunner', function () { ...@@ -95,8 +95,8 @@ describe('testRunner', function () {
}) })
}) })
// Test string comparision // Test string equality
describe('test with beforeAll', function () { describe('test string equality', function () {
let filename = 'tests/examples_3/simple_string_test.sol' let filename = 'tests/examples_3/simple_string_test.sol'
let tests = [], results = {} let tests = [], results = {}
...@@ -131,5 +131,31 @@ describe('testRunner', function () { ...@@ -131,5 +131,31 @@ describe('testRunner', function () {
]) ])
}) })
}) })
// Test signed/unsigned integer weight
describe('test number weight', function () {
let filename = 'tests/integer/integer_test.sol'
let tests = [], results = {}
before(function (done) {
compileAndDeploy(filename, function (_err, contracts) {
var testCallback = function (test) {
tests.push(test)
}
var resultsCallback = function (_err, _results) {
results = _results
done()
}
TestRunner.runTest('IntegerTest', contracts.IntegerTest, testCallback, resultsCallback)
})
})
it('should have 2 passing tests', function () {
assert.equal(results.passingNum, 2)
})
it('should have 1 failing tests', function () {
assert.equal(results.failureNum, 1)
})
})
}) })
}) })
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment