-
Notifications
You must be signed in to change notification settings - Fork 607
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
osmomath: AddMut
and QuoMut
#3779
Changes from 9 commits
28ac3a7
e0e2601
4978cbe
2870114
2faea41
0993272
5fec9f4
0a20620
0b22fd0
8be5795
f280099
8b11ef6
336e7b6
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
- mut add | ||
- test add mut | ||
- quo mut | ||
- test quo mut/ remove want from test struct | ||
|
||
<!-- < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < ☺ | ||
v ✰ Thanks for creating a PR! ✰ | ||
v Before smashing the submit button please review the checkboxes. | ||
v If a checkbox is n/a - please still include it but + a little note why | ||
v If your PR doesn't close an issue, that's OK! Just remove the Closes: #XXX line! | ||
☺ > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > --> | ||
|
||
Closes: #3773 | ||
|
||
## What is the purpose of the change | ||
mutative add and quo + tests |
Original file line number | Diff line number | Diff line change | ||
---|---|---|---|---|
|
@@ -38,6 +38,59 @@ func (s *decimalTestSuite) assertMutResult(expectedResult, startValue, mutativeR | |||
s.Require().Equal(nonMutativeStartValue, startValue) | ||||
} | ||||
|
||||
func TestAddMut(t *testing.T) { | ||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Since |
||||
tests := []struct { | ||||
testing osmomath.BigDec | ||||
adding osmomath.BigDec | ||||
}{ | ||||
{osmomath.NewBigDec(0), osmomath.NewBigDec(0)}, | ||||
{osmomath.NewBigDec(1), osmomath.NewBigDec(1)}, | ||||
{osmomath.NewBigDec(10), osmomath.NewBigDec(1)}, | ||||
{osmomath.NewBigDec(12340), osmomath.NewBigDec(10)}, | ||||
{osmomath.NewDecWithPrec(12340, 4), osmomath.NewDecWithPrec(12340, 4)}, | ||||
{osmomath.NewDecWithPrec(12340, 5), osmomath.NewDecWithPrec(12, 5)}, | ||||
{osmomath.NewDecWithPrec(12340, 8), osmomath.NewDecWithPrec(1009009009009009009, 8)}, | ||||
{osmomath.NewDecWithPrec(1009009009009009009, 17), osmomath.NewDecWithPrec(100, 17)}, | ||||
} | ||||
for _, tc := range tests { | ||||
want := tc.testing.Add(tc.adding) | ||||
tc.testing.AddMut(tc.adding) | ||||
|
||||
require.Equal(t, want, tc.testing) | ||||
} | ||||
} | ||||
|
||||
func TestQuoMut(t *testing.T) { | ||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same for this test case |
||||
tests := []struct { | ||||
testing osmomath.BigDec | ||||
quo osmomath.BigDec | ||||
|
||||
expectingErr bool | ||||
}{ | ||||
{osmomath.NewBigDec(0), osmomath.NewBigDec(0), true}, | ||||
{osmomath.NewBigDec(1), osmomath.NewBigDec(1), false}, | ||||
{osmomath.NewBigDec(10), osmomath.NewBigDec(1), false}, | ||||
{osmomath.NewBigDec(12340), osmomath.NewBigDec(10), false}, | ||||
{osmomath.NewDecWithPrec(12340, 4), osmomath.NewDecWithPrec(12340, 4), false}, | ||||
{osmomath.NewDecWithPrec(12340, 5), osmomath.NewDecWithPrec(12, 5), false}, | ||||
{osmomath.NewDecWithPrec(1009009009009009009, 8), osmomath.NewDecWithPrec(1000, 8), false}, | ||||
{osmomath.NewDecWithPrec(500, 17), osmomath.NewDecWithPrec(100, 17), false}, | ||||
} | ||||
for _, tc := range tests { | ||||
if !tc.expectingErr { | ||||
want := tc.testing.Quo(tc.quo) | ||||
tc.testing.QuoMut(tc.quo) | ||||
|
||||
require.Equal(t, want, tc.testing) | ||||
} else { | ||||
save := tc.testing | ||||
|
||||
require.Panics(t, func() { tc.testing.QuoMut(tc.quo) }) | ||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We have a helper for this here: osmosis/osmomath/export_test.go Line 25 in 6206709
|
||||
require.Equal(t, save, tc.testing) | ||||
} | ||||
|
||||
} | ||||
} | ||||
func TestDecApproxEq(t *testing.T) { | ||||
// d1 = 0.55, d2 = 0.6, tol = 0.1 | ||||
d1 := osmomath.NewDecWithPrec(55, 2) | ||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's remove this