int uint for greater and lesser than

pull/5370/head
aniket-engg 4 years ago committed by Aniket
parent b13c3447a2
commit 31e677ab72
  1. 19
      libs/remix-tests/sol/tests.sol.ts
  2. 4
      libs/remix-tests/src/assertionEvents.ts
  3. 8
      libs/remix-tests/tests/examples_0/assert_greaterThan_test.sol
  4. 8
      libs/remix-tests/tests/examples_0/assert_lesserThan_test.sol
  5. 24
      libs/remix-tests/tests/testRunner.spec.ts

@ -53,8 +53,15 @@ library Assert {
event AssertionEventUintInt(
bool passed,
string message,
uint returned,
int expected
uint256 returned,
int256 expected
);
event AssertionEventIntUint(
bool passed,
string message,
int256 returned,
uint256 expected
);
function ok(bool a, string memory message) public returns (bool result) {
@ -166,14 +173,14 @@ library Assert {
}
emit AssertionEventUintInt(result, message, a, b);
}
function greaterThan(int a, uint b, string memory message) public returns (bool result) {
function greaterThan(int256 a, uint256 b, string memory message) public returns (bool result) {
if(a < int(0)) {
// int is negative uint "b" always greater
result = false;
} else {
result = (uint(a) > b);
}
emit AssertionEvent(result, message);
emit AssertionEventIntUint(result, message, a, b);
}
/*----------------- Lesser than --------------------*/
function lesserThan(uint256 a, uint256 b, string memory message) public returns (bool result) {
@ -196,14 +203,14 @@ library Assert {
emit AssertionEventUintInt(result, message, a, b);
}
function lesserThan(int a, uint b, string memory message) public returns (bool result) {
function lesserThan(int256 a, uint256 b, string memory message) public returns (bool result) {
if(a < int(0)) {
// int is negative int "a" always lesser
result = true;
} else {
result = (uint(a) < b);
}
emit AssertionEvent(result, message);
emit AssertionEventIntUint(result, message, a, b);
}
}
`

@ -30,6 +30,10 @@ const assertionEvents = [
{
name: 'AssertionEventUintInt',
params: ['bool', 'string', 'uint256', 'int256']
},
{
name: 'AssertionEventIntUint',
params: ['bool', 'string', 'int256', 'uint256']
}
]

@ -25,4 +25,12 @@ contract AssertGreaterThanTest {
function greaterThanUintIntFailTest() public {
Assert.greaterThan(uint(1), int(2), "greaterThanUintIntFailTest fails");
}
function greaterThanIntUintPassTest() public {
Assert.greaterThan(int(10), uint(2), "greaterThanIntUintPassTest passes");
}
function greaterThanIntUintFailTest() public {
Assert.greaterThan(int(100), uint(-100), "greaterThanIntUintFailTest fails");
}
}

@ -25,4 +25,12 @@ contract AssertLesserThanTest {
function lesserThanUintIntFailTest() public {
Assert.lesserThan(uint(-1), int(-1), "lesserThanUintIntFailTest fails");
}
function lesserThanIntUintPassTest() public {
Assert.lesserThan(int(100), uint(-50), "lesserThanIntUintPassTest passes");
}
function lesserThanIntUintFailTest() public {
Assert.lesserThan(int(1), uint(1), "lesserThanIntUintFailTest fails");
}
}

@ -221,12 +221,12 @@ describe('testRunner', () => {
afterAll(() => { tests = [] })
it('should have 3 passing test', () => {
assert.equal(results.passingNum, 3)
it('should have 4 passing test', () => {
assert.equal(results.passingNum, 4)
})
it('should have 3 failing test', () => {
assert.equal(results.failureNum, 3)
it('should have 4 failing test', () => {
assert.equal(results.failureNum, 4)
})
it('should return', () => {
deepEqualExcluding(tests, [
@ -237,7 +237,9 @@ describe('testRunner', () => {
{ type: 'testPass', value: 'Greater than int pass test', context: 'AssertGreaterThanTest' },
{ type: 'testFailure', value: 'Greater than int fail test', errMsg: 'greaterThanIntFailTest fails', context: 'AssertGreaterThanTest', expected: '1', returned: '-1'},
{ type: 'testPass', value: 'Greater than uint int pass test', context: 'AssertGreaterThanTest' },
{ type: 'testFailure', value: 'Greater than uint int fail test', errMsg: 'greaterThanUintIntFailTest fails', context: 'AssertGreaterThanTest', expected: '2', returned: '1'}
{ type: 'testFailure', value: 'Greater than uint int fail test', errMsg: 'greaterThanUintIntFailTest fails', context: 'AssertGreaterThanTest', expected: '2', returned: '1'},
{ type: 'testPass', value: 'Greater than int uint pass test', context: 'AssertGreaterThanTest' },
{ type: 'testFailure', value: 'Greater than int uint fail test', errMsg: 'greaterThanIntUintFailTest fails', context: 'AssertGreaterThanTest', expected: '115792089237316195423570985008687907853269984665640564039457584007913129639836', returned: '100'}
], ['time'])
})
})
@ -253,12 +255,12 @@ describe('testRunner', () => {
afterAll(() => { tests = [] })
it('should have 3 passing test', () => {
assert.equal(results.passingNum, 3)
it('should have 4 passing test', () => {
assert.equal(results.passingNum, 4)
})
it('should have 3 failing test', () => {
assert.equal(results.failureNum, 3)
it('should have 4 failing test', () => {
assert.equal(results.failureNum, 4)
})
it('should return', () => {
@ -270,7 +272,9 @@ describe('testRunner', () => {
{ type: 'testPass', value: 'Lesser than int pass test', context: 'AssertLesserThanTest' },
{ type: 'testFailure', value: 'Lesser than int fail test', errMsg: 'lesserThanIntFailTest fails', context: 'AssertLesserThanTest', expected: '-1', returned: '1'},
{ type: 'testPass', value: 'Lesser than uint int pass test', context: 'AssertLesserThanTest' },
{ type: 'testFailure', value: 'Lesser than uint int fail test', errMsg: 'lesserThanUintIntFailTest fails', context: 'AssertLesserThanTest', expected: '-1', returned: '115792089237316195423570985008687907853269984665640564039457584007913129639935'}
{ type: 'testFailure', value: 'Lesser than uint int fail test', errMsg: 'lesserThanUintIntFailTest fails', context: 'AssertLesserThanTest', expected: '-1', returned: '115792089237316195423570985008687907853269984665640564039457584007913129639935'},
{ type: 'testPass', value: 'Lesser than int uint pass test', context: 'AssertLesserThanTest' },
{ type: 'testFailure', value: 'Lesser than int uint fail test', errMsg: 'lesserThanIntUintFailTest fails', context: 'AssertLesserThanTest', expected: '1', returned: '1'},
], ['time'])
})
})

Loading…
Cancel
Save