Skip to content

Instantly share code, notes, and snippets.

@zabirauf
Created January 16, 2018 03:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save zabirauf/c0a61062243afe4ede83ffd49c89b6cf to your computer and use it in GitHub Desktop.
Save zabirauf/c0a61062243afe4ede83ffd49c89b6cf to your computer and use it in GitHub Desktop.
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