MCPcopy
hub / github.com/josdejong/mathjs / checkExpectation

Function checkExpectation

test/node-tests/doc.test.js:146–192  ·  view source on GitHub ↗
(want, got)

Source from the content-addressed store, hash-verified

144}
145
146function checkExpectation (want, got) {
147 if (Array.isArray(want)) {
148 if (!Array.isArray(got)) {
149 got = want.valueOf()
150 }
151 return approxDeepEqual(got, want, 1e-9)
152 }
153 if (want instanceof math.Unit && got instanceof math.Unit) {
154 if (got.fixPrefix !== want.fixPrefix ||
155 got.skipAutomaticSimplification !== want.skipAutomaticSimplification
156 ) {
157 issueCount++
158 if (debug) {
159 console.log(' Note: Ignoring different flags in Unit comparison')
160 }
161 got.fixPrefix = want.fixPrefix
162 got.skipAutomaticSimplification = want.skipAutomaticSimplification
163 }
164 return approxDeepEqual(got, want, 1e-9)
165 }
166 if (want instanceof math.Complex && got instanceof math.Complex) {
167 return approxDeepEqual(got, want, 1e-9)
168 }
169 if (typeof want === 'number' && typeof got === 'number' && want !== got) {
170 issueCount++
171 if (debug) {
172 console.log(` Note: return value ${got} not exactly as expected: ${want}`)
173 }
174 return approxEqual(got, want, 1e-9)
175 }
176 if (
177 typeof want === 'string' &&
178 typeof got === 'string' &&
179 want.endsWith('Error') &&
180 got.startsWith(want)
181 ) {
182 return true // we obtained the expected error type
183 }
184 if (want && got && want.isBigNumber && got.isBigNumber) {
185 return approxEqual(got, want, 1e-50)
186 }
187 if (typeof want !== 'undefined') {
188 return approxDeepEqual(got, want)
189 } else {
190 // don't check if we don't know what the result is supposed to be
191 }
192}
193
194const OKundocumented = new Set([
195 'apply', // deprecated backwards-compatibility synonym of mapSlices

Callers 1

maybeCheckExpectationFunction · 0.85

Calls 4

approxDeepEqualFunction · 0.90
approxEqualFunction · 0.90
valueOfMethod · 0.65
logMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…