Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
S
swap-v2-sdk
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
LuckySwap
swap-v2-sdk
Commits
3b4f4a25
Commit
3b4f4a25
authored
May 06, 2020
by
Moody Salem
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add #remainder to the fraction entity
parent
22453c0c
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
18 additions
and
0 deletions
+18
-0
fraction.ts
src/entities/fractions/fraction.ts
+5
-0
fraction.test.ts
test/fraction.test.ts
+13
-0
No files found.
src/entities/fractions/fraction.ts
View file @
3b4f4a25
...
...
@@ -37,6 +37,11 @@ export class Fraction {
return
JSBI
.
divide
(
this
.
numerator
,
this
.
denominator
)
}
// remainder after floor division
get
remainder
():
Fraction
{
return
this
.
subtract
(
this
.
quotient
)
}
invert
():
Fraction
{
return
new
Fraction
(
this
.
denominator
,
this
.
numerator
)
}
...
...
test/fraction.test.ts
View file @
3b4f4a25
...
...
@@ -9,6 +9,19 @@ describe.only('Fraction', () => {
expect
(
new
Fraction
(
JSBI
.
BigInt
(
16
),
JSBI
.
BigInt
(
5
)).
quotient
).
toEqual
(
JSBI
.
BigInt
(
3
))
// one above
})
})
describe
(
'
#remainder
'
,
()
=>
{
it
(
'
returns fraction after divison
'
,
()
=>
{
expect
(
new
Fraction
(
JSBI
.
BigInt
(
8
),
JSBI
.
BigInt
(
3
)).
remainder
).
toEqual
(
new
Fraction
(
JSBI
.
BigInt
(
2
),
JSBI
.
BigInt
(
3
))
)
expect
(
new
Fraction
(
JSBI
.
BigInt
(
12
),
JSBI
.
BigInt
(
4
)).
remainder
).
toEqual
(
new
Fraction
(
JSBI
.
BigInt
(
0
),
JSBI
.
BigInt
(
4
))
)
expect
(
new
Fraction
(
JSBI
.
BigInt
(
16
),
JSBI
.
BigInt
(
5
)).
remainder
).
toEqual
(
new
Fraction
(
JSBI
.
BigInt
(
1
),
JSBI
.
BigInt
(
5
))
)
})
})
describe
(
'
#invert
'
,
()
=>
{
it
(
'
flips num and denom
'
,
()
=>
{
expect
(
new
Fraction
(
JSBI
.
BigInt
(
5
),
JSBI
.
BigInt
(
10
)).
invert
().
numerator
).
toEqual
(
JSBI
.
BigInt
(
10
))
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment