Add Arrays library with unit tests (#1209) (#1375)

*     Add Arrays library with unit tests (#1209)

    * prepared due to snapshot token requirements
    * add library with method to find upper bound
    * add unit test for basic and edge cases

* Imporove documentation for Arrays library

Simplify Arrays.test.js to use short arrays as test date

* Added comment for uint256 mid variable.
* Explaned why uint256 mid variable calculated as Math.average is safe to use as index of array.

(cherry picked from commit f7e53d90fa)
This commit is contained in:
Jakub Bogacz
2018-10-08 16:01:33 +02:00
committed by Nicolás Venturo
parent 66bad4ff2a
commit 8d6250cd5a
3 changed files with 161 additions and 0 deletions

View File

@ -0,0 +1,18 @@
pragma solidity ^0.4.24;
import "../utils/Arrays.sol";
contract ArraysImpl {
using Arrays for uint256[];
uint256[] private array;
constructor(uint256[] _array) public {
array = _array;
}
function findUpperBound(uint256 _element) external view returns (uint256) {
return array.findUpperBound(_element);
}
}