77 getCoefficients ,
88 setXToOne ,
99 solveLinearEquation ,
10+ solveQuadraticEquation ,
1011 expressionsCanBeCompared ,
1112 transformEqualityInExpression ,
1213} from "../symbolic/utils" ;
@@ -107,7 +108,7 @@ describe("getCoefficients", () => {
107108 ${ "x - x - 2" } | ${ [ ] }
108109 ` ( "$expression => $coefficients" , ( { expression, coefficients } ) => {
109110 const equation = atm . convert ( lta . convert ( expression ) ) ;
110- const coefficientsList = getCoefficients ( equation ) ;
111+ const coefficientsList = getCoefficients ( equation , false ) ;
111112
112113 expect ( coefficientsList ) . toEqual ( coefficients ) ;
113114 } ) ;
@@ -116,21 +117,21 @@ describe("getCoefficients", () => {
116117describe ( "getCoefficients" , ( ) => {
117118 it ( 'equation: "x = x" - has coefficients [0, 0]' , ( ) => {
118119 const equation = atm . convert ( lta . convert ( "x-x" ) ) ;
119- const coefficientsList = getCoefficients ( equation ) ;
120+ const coefficientsList = getCoefficients ( equation , false ) ;
120121
121122 expect ( coefficientsList ) . toEqual ( [ 0 , 0 ] ) ;
122123 } ) ;
123124
124125 it ( 'equation: "1 = -2" - if equation has no coefficient for x but can be rationalized it will return an empty array' , ( ) => {
125126 const equation = atm . convert ( lta . convert ( "1+2" ) ) ;
126- const coefficientsList = getCoefficients ( equation ) ;
127+ const coefficientsList = getCoefficients ( equation , false ) ;
127128
128129 expect ( coefficientsList ) . toEqual ( [ ] ) ;
129130 } ) ;
130131
131132 it ( 'equation: "m + n = - 2" - if equation has more than one variable, will return coefficients [1, 0]' , ( ) => {
132133 const equation = atm . convert ( lta . convert ( "m+n = - 2" ) ) ;
133- const coefficientsList = getCoefficients ( equation ) ;
134+ const coefficientsList = getCoefficients ( equation , false ) ;
134135
135136 expect ( coefficientsList ) . toEqual ( [ 1 , 0 ] ) ;
136137 } ) ;
@@ -172,6 +173,26 @@ describe("solveLinearEquation", () => {
172173 } ) ;
173174} ) ;
174175
176+ describe ( "solveQuadraticEquation" , ( ) => {
177+ it . each `
178+ coefficients | roots
179+ ${ [ 14 , - 9 , 1 ] } | ${ [ { re : 7 , im : 0 } , { re : 2 , im : 0 } ] }
180+ ${ [ - 3 , 2 , 8 ] } | ${ [ { re : 0.5 , im : 0 } , { re : - 0.75 , im : 0 } ] }
181+ ${ [ 8 , 6 , 2 ] } | ${ [ { re : - 1.5 , im : 1.3228756555323 } , { re : - 1.5 , im : - 1.3228756555323 } ] }
182+ ${ [ 6 , 5 , 1 ] } | ${ [ { re : - 2 , im : 0 } , { re : - 3 , im : 0 } ] }
183+ ${ [ 3 , - 7 , 2 ] } | ${ [ { re : 3 , im : 0 } , { re : 1 / 2 , im : 0 } ] }
184+ ${ [ 1 , 3 , 2 ] } | ${ [ { re : - 0.5 , im : 0 } , { re : - 1 , im : 0 } ] }
185+ ${ [ - 3 , 2 , 1 ] } | ${ [ { re : 1 , im : 0 } , { re : - 3 , im : 0 } ] }
186+ ${ [ - 9 , 0 , 1 ] } | ${ [ { re : 3 , im : 0 } , { re : - 3 , im : 0 } ] }
187+ ${ [ - 8 , - 5 , 3 ] } | ${ [ { re : 2.6666666666667 , im : 0 } , { re : - 1 , im : 0 } ] }
188+ ${ [ 17 , - 5 , 4 ] } | ${ [ { re : 0.625 , im : 1.9645292056877 } , { re : 0.625 , im : - 1.9645292056877 } ] }
189+ ` ( "$coefficients => $roots" , ( { coefficients, roots } ) => {
190+ const result = solveQuadraticEquation ( coefficients ) ;
191+
192+ expect ( result ) . toEqual ( roots ) ;
193+ } ) ;
194+ } ) ;
195+
175196describe ( "solveLinearEquation" , ( ) => {
176197 it ( 'equation: "x = x" - has infinite solutions' , ( ) => {
177198 const coefficients = [ 0 , 0 ] ;
0 commit comments