浏览代码

Merge pull request #601 from elopio/test/math

test: add tests for max64 and min64 from Math
Francisco Giordano 7 年之前
父节点
当前提交
462c52bcbf
共有 2 个文件被更改,包括 42 次插入0 次删除
  1. 25 0
      test/Math.test.js
  2. 17 0
      test/mocks/MathMock.sol

+ 25 - 0
test/Math.test.js

@@ -0,0 +1,25 @@
+var MathMock = artifacts.require('./mocks/MathMock.sol');
+
+contract('Math', function (accounts) {
+  let math;
+
+  before(async function () {
+    math = await MathMock.new();
+  });
+
+  it('returns max correctly', async function () {
+    let a = 5678;
+    let b = 1234;
+    await math.max64(a, b);
+    let result = await math.result();
+    assert.equal(result, a);
+  });
+
+  it('returns min correctly', async function () {
+    let a = 5678;
+    let b = 1234;
+    await math.min64(a, b);
+    let result = await math.result();
+    assert.equal(result, b);
+  });
+});

+ 17 - 0
test/mocks/MathMock.sol

@@ -0,0 +1,17 @@
+pragma solidity ^0.4.18;
+
+
+import '../../contracts/math/Math.sol';
+
+
+contract MathMock {
+  uint64 public result;
+
+  function max64(uint64 a, uint64 b) public {
+    result = Math.max64(a, b);
+  }
+
+  function min64(uint64 a, uint64 b) public {
+    result = Math.min64(a, b);
+  }
+}