Created
January 16, 2018 03:20
-
-
Save zabirauf/c0a61062243afe4ede83ffd49c89b6cf to your computer and use it in GitHub Desktop.
This file contains hidden or 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
pragma solidity ^0.4.15; | |
import "truffle/Assert.sol"; | |
import { StringToUintMap } from "../libraries/StringToUintMap.sol"; | |
contract TestStringToUintMap { | |
StringToUintMap.Data private _stringToUintMapData; | |
function testInsertNewKey() { | |
// Arrange | |
string memory key = "test1"; | |
uint8 value = 10; | |
// Act | |
StringToUintMap.insert(_stringToUintMapData, key, value); | |
// Assert | |
Assert.equal(uint(_stringToUintMapData.map[key]), uint(value), "The key should be added"); | |
} | |
function testUpdateKey() { | |
// Arrange | |
string memory key = "test2"; | |
StringToUintMap.insert(_stringToUintMapData, key, 10); | |
// Act | |
uint8 newValue = 20; | |
bool updated = StringToUintMap.insert(_stringToUintMapData, key, newValue); | |
// Assert | |
Assert.isTrue(updated, "The value should be updated"); | |
Assert.equal(uint(_stringToUintMapData.map[key]), uint(newValue), "The value should be updated"); | |
} | |
function testGetValue() { | |
// Arrange | |
string memory key = "test3"; | |
uint8 value = 10; | |
StringToUintMap.insert(_stringToUintMapData, key, value); | |
// Act | |
uint8 result = StringToUintMap.get(_stringToUintMapData, key); | |
// Assert | |
Assert.equal(uint(result), uint(value), "The key should have value"); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment