Some tests, seems it is working
This commit is contained in:
parent
bc38acbff6
commit
5fabb4424c
1 changed files with 31 additions and 0 deletions
|
|
@ -1,6 +1,7 @@
|
||||||
import 'package:d4rt_formulas/formula_evaluator.dart';
|
import 'package:d4rt_formulas/formula_evaluator.dart';
|
||||||
import 'package:d4rt_formulas/formula_models.dart';
|
import 'package:d4rt_formulas/formula_models.dart';
|
||||||
import 'package:flutter_test/flutter_test.dart';
|
import 'package:flutter_test/flutter_test.dart';
|
||||||
|
import 'dart:math' as Math;
|
||||||
|
|
||||||
|
|
||||||
void main() {
|
void main() {
|
||||||
|
|
@ -10,6 +11,13 @@ void main() {
|
||||||
expect(root, closeTo(0, 0.1));
|
expect(root, closeTo(0, 0.1));
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
|
test("Solve (x-1000)^2", () {
|
||||||
|
Number f(Number x) => (x-1000)*(x-1000);
|
||||||
|
var root = functionSolver(f, hint: 10, step: 1, maxTries: 1000);
|
||||||
|
expect(root, closeTo(1000, 0.1));
|
||||||
|
});
|
||||||
|
|
||||||
test("Solve x^2 + 1", () {
|
test("Solve x^2 + 1", () {
|
||||||
Number f(Number x) => x*x+1;
|
Number f(Number x) => x*x+1;
|
||||||
|
|
||||||
|
|
@ -22,5 +30,28 @@ void main() {
|
||||||
expect( functionSolver(f, hint: 10, step: 1), closeTo(10, 0.1));
|
expect( functionSolver(f, hint: 10, step: 1), closeTo(10, 0.1));
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test('Solve sqrt(x) = 2 => x = 4', () {
|
||||||
|
Number f(Number x) => Math.sqrt(x) - 2;
|
||||||
|
var root = functionSolver(f, hint: 5, step: 1);
|
||||||
|
expect(root, closeTo(4, 0.1));
|
||||||
|
});
|
||||||
|
|
||||||
|
test('Solve sin(x) = 0 near pi (hint 3)', () {
|
||||||
|
Number f(Number x) => Math.sin(x);
|
||||||
|
var root = functionSolver(f, hint: 3, step: 1);
|
||||||
|
expect(root, closeTo(Math.pi, 0.01));
|
||||||
|
});
|
||||||
|
|
||||||
|
test('Solve tan(x) = 1 => x = pi/4', () {
|
||||||
|
Number f(Number x) => Math.tan(x) - 1;
|
||||||
|
var root = functionSolver(f, hint: 0, step: 1);
|
||||||
|
expect(root, closeTo(Math.pi / 4, 0.01));
|
||||||
|
});
|
||||||
|
|
||||||
|
test('Solve exp(x) = 2 => x = ln(2)', () {
|
||||||
|
Number f(Number x) => Math.exp(x) - 2;
|
||||||
|
var root = functionSolver(f, hint: 1, step: 1);
|
||||||
|
expect(root, closeTo(Math.log(2), 0.01));
|
||||||
|
});
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue