Skip to content

Fractions #50

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

Open
wants to merge 62 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
62 commits
Select commit Hold shift + click to select a range
04bb0ee
added rules for patterns w/o constraints
aliang8 Apr 30, 2017
f37f48c
added rules test, some errors
aliang8 Apr 30, 2017
5745443
rm file
aliang8 Apr 30, 2017
b462d8a
rm file
aliang8 Apr 30, 2017
3ca4c7f
format
aliang8 Apr 30, 2017
adcbc10
fixed tabing, remove comments, added rules, need to check variables
aliang8 Apr 30, 2017
3cb89d4
added extra test cases, not done
aliang8 Apr 30, 2017
75ab164
not sure what's up with these tests
aliang8 Apr 30, 2017
3beef3e
finished adding cases, still some errors
aliang8 May 1, 2017
c35f087
fixed merge errors
aliang8 May 2, 2017
20bc705
one last test
aliang8 May 2, 2017
336c5c3
fixed tests and yarn
aliang8 May 2, 2017
3dbb8cd
done
aliang8 May 2, 2017
2335275
removed lint, added TODO
aliang8 May 2, 2017
d91eb26
merging
aliang8 May 5, 2017
7fdbd7e
rebasing
aliang8 May 7, 2017
e8e86a1
merge
aliang8 May 9, 2017
7a3e271
merged
aliang8 May 10, 2017
fbd4938
merge
aliang8 May 14, 2017
3ea7468
merge
aliang8 May 15, 2017
96d2bb9
merged
aliang8 May 18, 2017
caa0ae0
addingPolynomials
aliang8 May 20, 2017
14a091f
fixed comments
aliang8 May 20, 2017
aa21a98
added more tests, one of them fails
aliang8 May 20, 2017
08b3ca1
remove . file
aliang8 May 20, 2017
03ffdf1
merge
aliang8 May 20, 2017
648f0f7
remove alphabetize
aliang8 May 20, 2017
632b525
fixed comments
aliang8 May 20, 2017
7403644
removed comment
aliang8 May 20, 2017
2cb2f76
starting to work on LCM
aliang8 May 20, 2017
fa1c35c
fractional polynomial and rearrange coeffs
aliang8 May 21, 2017
85f51d0
remove . file
aliang8 May 21, 2017
9f81447
fixed failing case
aliang8 May 21, 2017
9781f2d
fixed comments
aliang8 May 21, 2017
51885d6
back to master
aliang8 May 22, 2017
99deef2
Merge branch 'master' into master
aliang8 May 25, 2017
fd811ac
merge w/master
aliang8 Jun 5, 2017
a3715ff
merge
aliang8 Jun 5, 2017
9f29c4e
added common-denom
aliang8 Jun 8, 2017
28e3d34
merge
aliang8 Jun 12, 2017
e83c322
updating fractions function
aliang8 Jun 14, 2017
e7ff24f
fixed common denoms
aliang8 Jun 15, 2017
3c83192
remove comments
aliang8 Jun 15, 2017
4eac6c4
comment out test case
aliang8 Jun 15, 2017
41ceb20
added rewrite fractional polynomial
aliang8 Jun 15, 2017
a868faf
fixed case for number + fraction
aliang8 Jun 18, 2017
d55286f
rm dot file
aliang8 Jun 18, 2017
0a7e6aa
general case
aliang8 Jun 18, 2017
25dda64
refactored negatives logic
aliang8 Jun 18, 2017
5c9274a
made output more friendly
aliang8 Jun 18, 2017
7d8e286
few more edge cases
aliang8 Jun 18, 2017
e45f4a3
added a convert to fraction rule
aliang8 Jun 18, 2017
05e2c52
added decimal_to_fraction function
aliang8 Jun 18, 2017
410afe5
small fix
aliang8 Jun 18, 2017
da0efa6
an extra test case
aliang8 Jun 18, 2017
e7c80ac
change to if statements
aliang8 Jun 18, 2017
8164020
still fixing test case
aliang8 Jun 19, 2017
d31d216
working on simplify_terms
aliang8 Jun 20, 2017
783d092
almost done with simplify terms
aliang8 Jun 20, 2017
6396397
fix edge cases
aliang8 Jun 20, 2017
1893d87
fixing common denominator
aliang8 Jun 20, 2017
43c63ea
adding comments and fixed paren issue
aliang8 Jun 21, 2017
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
78 changes: 72 additions & 6 deletions lib/__test__/rule-list.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -172,21 +172,86 @@ describe('rules', () => {
['x^((x + 1) / -1)', 'x^(-(x + 1) / 1)'],
])

suite('add numerators', rules.COMBINE_NUMERATORS, [
suite('rewrite fractional polynomial', rules.REWRITE_FRACTIONAL_POLYNOMIAL, [
['2x/3', '2 / 3 x'],
['2x^2/3', '2 / 3 x^2'],
['2(x+1)^2/3', '2 / 3 (x + 1)^2'],
['2xyz/3', '2 / 3 xyz'],
])

suite('combine numerators', rules.COMBINE_NUMERATORS, [
['1/3 + 2/3', '(1 + 2) / 3'],
['1/x + 2/x + 3/x', '(1 + 2 + 3) / x'],
['2/3 - 1/3', '(2 - 1) / 3'],
['(1/3 + 2/3) / x', '(1 + 2) / 3 / x'],
])

suite('common denominators', rules.COMMON_DENOMINATOR, [
suite('convert to fraction', rules.CONVERT_TO_FRACTION, [
['2/3 + x', '2 / 3 + x / 1'],
['2/3 - x', '2 / 3 - x / 1'],
['2/3 - x - 2', '2 / 3 - x / 1 - 2 / 1'],
['2/(3 + x) + 2 + (x + 1)^2', '2 / (3 + x) + 2 / 1 + (x + 1)^2 / 1'],
['2.2 + 3/4', '11 / 5 + 3 / 4'],
['1.33 + 2.12 + 2/3', '133 / 100 + 53 / 25 + 2 / 3'],
['1.44 - 2 - 3/4', '36 / 25 - 2 / 1 - 3 / 4'],
['-2 + 3.33 + 2/3', '-2 / 1 + 333 / 100 + 2 / 3']
])

suite('cancel like terms', rules.CANCEL_LIKE_TERMS, [
// when all factors cancel
['((x+1)(x+2)) / ((x+1)(x+2))', '1'],
['(x y z) / (x y z)', '1'],
// one factor in numerator, none in denominator
['(12(x+1)) / (x+1)', '12'],
['(x y z) / (y z)', 'x'],
// TODO: handle nthRoots
//['nthRoot(x^2,2) nthRoot(x^3,3) / nthRoot(x^2,2)']
// multiple factors in numerator, none in denominator
['(12(x+1)^2) / (x+1)', '12 (x + 1)^1'],
['(x y z w) / (z w)', 'x y'],
// one factor in denominator, none in numerator
['(x+1)^2 / (12(x+1)^2)', '1 / 12'],
['(x y z) / (x y z w)', '1 / w'],
// multiple factors in denominator, none in numerator
['(x+1)^2 / (12 (x+1)^3)', '1 / (12 (x + 1)^1)'],
['(x y z) / (x y z a b c)', '1 / (a b c)'],
// one factor in numerator and denominator
['((x+1)^2 (x+2)^3) / ((x+1)^2 (x+3)^3)', '(x + 2)^3 / (x + 3)^3'],
['(x y z) / (y z w)', 'x / w'],
// one factor in denominator, multiple in numerator
['(12(x+1)^2 (2x+1)^2) / (x+1)^3 ', '(12 (2 x + 1)^2) / (x + 1)^1'],
// one factor in numerator, multiple in denominator
['(x+1)^3 / (12(x+1)^2 (x+2)^3)', '(x + 1)^1 / (12 (x + 2)^3)'],
['(x y z) / (y z a b)', 'x / (a b)'],
// multiple factors in both numerator and denominator
['(12(x+1)^2 (x+2)^2) / ((x+2)^3 (x+4)^2)', '(12 (x + 1)^2) / ((x + 2)^1 (x + 4)^2)'],
['(a b c d) / (d e f g)', '(a b c) / (e f g)'],
// testing simplify fractions
['(12(x+1)^2) / (8(x+2))', '(3 (x + 1)^2) / (2 (x + 2))'],
])

suite('common denominators', rules.COMMON_DENOMINATOR, [
['2/6 + 1/4', '(2 * 2) / (6 * 2) + (1 * 3) / (4 * 3)'],
['2/(3 + x) + 3/(2 + x)', '(2 (2 + x)) / ((3 + x) (2 + x)) + (3 (3 + x)) / ((3 + x) (2 + x))'],
['2/5 + 1/(3x + 7)', '(2 (3 x + 7)) / (5 (3 x + 7)) + (1 * 5) / (5 (3 x + 7))'],
['2/6 - 1/4', '(2 * 2) / (6 * 2) - (1 * 3) / (4 * 3)'],
['2/6 + 1/4 - 2/5', '(2 * 10) / (6 * 10) + (1 * 15) / (4 * 15) - (2 * 12) / (5 * 12)'],
['2/6 + 1/4 - 3/4', '(2 * 2) / (6 * 2) + (1 * 3) / (4 * 3) - (3 * 3) / (4 * 3)'],
// TODO: return the original expression if the denominators are already
// the same?
['2/4 - 1/4', '(2 * 1) / (4 * 1) - (1 * 1) / (4 * 1)'],
['2/6 + 1/4 - 3/4', '(2 * 2) / (6 * 2) + (1 * 3) / (4 * 3) - (3 * 3) / (4 * 3)'],
['(3 + x)/2 + 2/(3 + x) + 2/3', '((3 + x) 3 (3 + x)) / (6 (3 + x)) + (2 * 6) / (6 (3 + x)) + (2 2 (3 + x)) / (6 (3 + x))'],
// Some terms have same denom
['2/3 + 2/3 + 1/4 + 1/4', '(2 * 4) / (3 * 4) + (2 * 4) / (3 * 4) + (1 * 3) / (4 * 3) + (1 * 3) / (4 * 3)'],
// Number surrounded by fraction
['3 + 2/3', '(3 * 3) / 3 + 2 / 3'],
['x + 2 + 3/4', '(x * 4) / 4 + (2 * 4) / 4 + 3 / 4'],
['(x + 1)^2 + 2/3', '((x + 1)^2 * 3) / 3 + 2 / 3'],
['2(x + 1)^2 + 2/3', '(2 (x + 1)^2 * 3) / 3 + 2 / 3'],
['2/3 - x - 2', '2 / 3 - (x * 3) / 3 - (2 * 3) / 3'],
['2/3 - x/3 - 2/4', '(2 * 4) / (3 * 4) - (x * 4) / (3 * 4) - (2 * 3) / (4 * 3)'],
['-2 + 3 - 2/4', '-(2 * 4) / 4 + (3 * 4) / 4 - 2 / 4'],
['2 / x + 3 / (x + 1)^2', '(2 (x + 1)^2) / (x (x + 1)^2) + (3 x) / (x (x + 1)^2)'],
['2 / (4 * x) + 2 / y', '(2 y) / (4 x y) + (2 (4 x)) / (4 x y)'],
// TODO: case doesn't work, but is fine because polynomials should be simplified
//['2 / (x * x) + 3 / (x * y) + 4 / (y * y)', ''],
])

suite('multiply fractions', rules.MULTIPLY_FRACTIONS, [
Expand Down Expand Up @@ -491,3 +556,4 @@ describe('canApplyRule', () => {
})
})
})

Loading