-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #161 from notJoon/pool-tick-math
refactor: pool/tick_math.gno
- Loading branch information
Showing
2 changed files
with
175 additions
and
105 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
package pool | ||
|
||
import ( | ||
"testing" | ||
) | ||
|
||
func TestFindMSB(t *testing.T) { | ||
tests := []struct { | ||
name string | ||
ratio bigint | ||
expectedMSB bigint | ||
expectedRatio bigint | ||
}{ | ||
{ | ||
name: "very low ratio", | ||
ratio: bigint(1<<10), | ||
expectedMSB: 10, | ||
expectedRatio: 1, | ||
}, | ||
{ | ||
name: "low ratio", | ||
ratio: bigint(1<<30), | ||
expectedMSB: 30, | ||
expectedRatio: 1, | ||
}, | ||
{ | ||
name: "medium ratio", | ||
ratio: bigint(1<<50), | ||
expectedMSB: 50, | ||
expectedRatio: 1, | ||
}, | ||
{ | ||
name: "high ratio", | ||
ratio: 1<<100, | ||
expectedMSB: 100, | ||
expectedRatio: 1, | ||
}, | ||
{ | ||
name: "very high ratio", | ||
ratio: 1<<110, | ||
expectedMSB: 110, | ||
expectedRatio: 1, | ||
}, | ||
{ | ||
name: "extreme ratio", | ||
ratio: 1<<200, | ||
expectedMSB: 200, | ||
expectedRatio: 1, | ||
}, | ||
} | ||
|
||
for _, tt := range tests { | ||
t.Run(tt.name, func(t *testing.T) { | ||
msb, ratio := findMSB(tt.ratio) | ||
|
||
if msb != tt.expectedMSB { | ||
t.Errorf("expected MSB to be %d, got %d", tt.expectedMSB, msb) | ||
} | ||
|
||
if ratio != tt.expectedRatio { | ||
t.Errorf("expected ratio to be %d, got %d", tt.expectedRatio, ratio) | ||
} | ||
}) | ||
} | ||
} |
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