Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add semantic tests for bin number literals
- Loading branch information
Showing
2 changed files
with
105 additions
and
0 deletions.
There are no files selected for viewing
47 changes: 47 additions & 0 deletions
47
test/libsolidity/semanticTests/various/bin_number_literal_operator_complex.sol
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
contract test { | ||
function complex_random_arithmetics() public pure returns (uint d) { | ||
uint a = ((0b1101 + 0b101010 - 0b1011) << 2) * (0b100011 & 0b11111) + ((0b1100 ^ 0b1011) >> 1) * (0b1110 % 0b101) % 0b101000011; | ||
uint b = (((0b100011 * 0b11) + (0b1100 ^ 0b1011)) & 0b111111) * ((0b1010101 % (0b11001 + 0b1110)) << 3); | ||
uint c = ((0b1001 + 0b111 - 0b11) * (0b1 & 0b1111) + (0b10111 ^ 0b1101) + (0b1100101 & 0b100011)) >> 2 * (0b1001 + 0b1011 << 1); | ||
d = (a + b + c * (0b101 & 0b11111) + (0b11100 | 0b1010) + (0b1101 ^ (0b1010 << 2))) % 0b1000000000000000000000000000000000000000000000000000000000000001; | ||
} | ||
function complex_fibonacci_identity() public pure returns (uint c) { | ||
// \sum_{i=0}^{n - 1} F_{i} ** 2 == F_{n - 1} * F_{n} | ||
c += 0b0 * 0b0; | ||
c += 0b1 * 0b1; | ||
c += 0b1 * 0b1; | ||
c += 0b10 * 0b10; | ||
c += 0b11 * 0b11; | ||
c += 0b101 * 0b101; | ||
c += 0b1000 * 0b1000; | ||
c += 0b1101 * 0b1101; | ||
c += 0b10101 * 0b10101; | ||
c += 0b100010 * 0b100010; | ||
c += 0b110111 * 0b110111; | ||
c += 0b1011001 * 0b1011001; | ||
c += 0b10010000 * 0b10010000; | ||
c += 0b11101001 * 0b11101001; | ||
c += 0b101111001 * 0b101111001; | ||
c += 0b1001100010 * 0b1001100010; | ||
c += 0b1111011011 * 0b1111011011; | ||
c += 0b11000111101 * 0b11000111101; | ||
c += 0b101000011000 * 0b101000011000; | ||
c += 0b1000001010101 * 0b1000001010101; | ||
c += 0b1101001101101 * 0b1101001101101; | ||
c += 0b10101011000010 * 0b10101011000010; | ||
c -= 0b10101011000010 * 0b100010100101111; | ||
} | ||
function complex_vandermonde_determinant() public pure returns (uint e) { | ||
// [[1, 1, 1, 1], [1, 2, 4, 8], [1, 3, 9, 27], [1, 4, 16, 64]] | ||
uint a = (0b10 * (0b1001 * 0b1000000 - 0b11011 * 0b10000) - 0b100 * (0b11 * 0b1000000 - 0b11011 * 0b100) + 0b1000 * (0b11 * 0b10000 - 0b1001 * 0b100)); | ||
uint b = (0b1 * (0b1001 * 0b1000000 - 0b11011 * 0b10000) - 0b100 * (0b1 * 0b1000000 - 0b11011 * 0b1) + 0b1000 * (0b1 * 0b10000 - 0b1001 * 0b1)); | ||
uint c = (0b1 * (0b11 * 0b1000000 - 0b11011 * 0b100) - 0b10 * (0b1 * 0b1000000 - 0b11011 * 0b1) + 0b1000 * (0b1 * 0b100 - 0b11 * 0b1)); | ||
uint d = (0b1 * (0b11 * 0b10000 - 0b1001 * 0b100) - 0b10 * (0b1 * 0b10000 - 0b1001 * 0b1) + 0b100 * (0b1 * 0b100 - 0b11 * 0b1)); | ||
e = a + c; | ||
e -= b + d; | ||
} | ||
} | ||
// ---- | ||
// complex_random_arithmetics() -> 0xcdf | ||
// complex_fibonacci_identity() -> 0x0 | ||
// complex_vandermonde_determinant() -> 0xc |
58 changes: 58 additions & 0 deletions
58
test/libsolidity/semanticTests/various/bin_number_literal_operator_simple.sol
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
contract test { | ||
function add() public pure returns (uint c) { | ||
c = 0b01 + 0b110; | ||
} | ||
function sub() public pure returns (uint c) { | ||
c = 0b0111110 - 0b110; | ||
} | ||
function mul() public pure returns (uint c) { | ||
c = 0b110 * 0b01011; | ||
} | ||
function div() public pure returns (uint c) { | ||
c = 0b10111 / uint256(0b11); | ||
} | ||
function mod() public pure returns (uint c) { | ||
c = 0b110101010 % 0b1011; | ||
} | ||
function xor() public pure returns (uint c) { | ||
c = 0b110101 ^ 0b001010; | ||
} | ||
function and() public pure returns (uint c) { | ||
c = 0b110010 & 0b010101; | ||
} | ||
function or() public pure returns (uint c) { | ||
c = 0b101010 | 0b110001; | ||
} | ||
function shiftleft() public pure returns (uint c) { | ||
c = 0b11111111 << 0b10000; | ||
} | ||
function shiftright() public pure returns (uint c) { | ||
c = 0b111111110000000000000000 >> 0b10000; | ||
} | ||
function compound_add() public pure returns (uint c) { | ||
c = 0b11110011000; | ||
c += 0b00001100111; | ||
} | ||
function compound_sub() public pure returns (uint c) { | ||
c = 0b1111111111; | ||
c -= 0b1010101010; | ||
} | ||
function compound_mul() public pure returns (uint c) { | ||
c = 0b110101011; | ||
c *= 0b10110101; | ||
} | ||
} | ||
// ---- | ||
// add() -> 0x7 | ||
// sub() -> 0x38 | ||
// mul() -> 0x42 | ||
// div() -> 0x7 | ||
// mod() -> 0x8 | ||
// xor() -> 0x3f | ||
// and() -> 0x10 | ||
// or() -> 0x3b | ||
// shiftleft() -> 0xff0000 | ||
// shiftright() -> 0xff | ||
// compound_add() -> 0x7ff | ||
// compound_sub() -> 0x155 | ||
// compound_mul() -> 0x12de7 |