Created
March 15, 2022 13:02
-
-
Save metashx/f1261655f628a0d8ffbd7aa62d585c2f to your computer and use it in GitHub Desktop.
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
// SPDX-License-Identifier: MIT | |
pragma solidity 0.8.7; | |
import {DSTest} from "ds-test/test.sol"; | |
contract Which { | |
uint256[] public s_playerFunds; | |
uint256 public s_totalFunds; | |
constructor() { | |
s_playerFunds = [ | |
1, | |
15, | |
22, | |
199, | |
234, | |
5, | |
234, | |
5, | |
2345, | |
234, | |
555, | |
23423, | |
55 | |
]; | |
} | |
function a() public { | |
uint256 totalFunds; | |
for (uint256 i = 0; i < s_playerFunds.length; i++) { | |
totalFunds = totalFunds + s_playerFunds[i]; | |
} | |
s_totalFunds = totalFunds; | |
} | |
function b() external { | |
for (uint256 i = 0; i < s_playerFunds.length; i++) { | |
s_totalFunds += s_playerFunds[i]; | |
} | |
} | |
function c() public { | |
uint256 totalFunds; | |
uint256[] memory playerFunds = s_playerFunds; | |
for (uint256 i = 0; i < playerFunds.length; i++) { | |
totalFunds = totalFunds + playerFunds[i]; | |
} | |
s_totalFunds = totalFunds; | |
} | |
} | |
contract WhichTest is DSTest { | |
Which internal which; | |
function setUp() public { | |
which = new Which(); | |
} | |
function testA() public { | |
which.a(); | |
} | |
function testB() public { | |
which.b(); | |
} | |
function testC() public { | |
which.c(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment