add number weight tests

pull/5370/head
0mkar 7 years ago
parent 1110dcba09
commit 0e43174dee
  1. 40
      remix-tests/sol/tests.sol.js
  2. 15
      remix-tests/tests/integer/integer_test.sol
  3. 30
      remix-tests/tests/testRunner.js

@ -97,5 +97,45 @@ library Assert {
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
}
`

@ -0,0 +1,15 @@
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 () {
})
})
// Test string comparision
describe('test with beforeAll', function () {
// Test string equality
describe('test string equality', function () {
let filename = 'tests/examples_3/simple_string_test.sol'
let tests = [], results = {}
@ -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)
})
})
})
})

Loading…
Cancel
Save