1
0
Fork 0
flutter_demo_energy/test/algorithms/energy_test.dart

65 lines
2.0 KiB
Dart

import 'package:energy/algorithms/energy.dart';
import 'package:test/test.dart';
void main() {
const double oneTon = 1000.0; // kg
const double tenToStop = 50000.0; // J
const double oneTonTenMetersDown = 98100.0; // J
group('energy', () {
test('none', () {
expect(freedEnergy(oneTon, 0, 0, 0, 0), 0);
expect(freedEnergy(oneTon, 0, 0, 20, 20), 0);
});
group('potential', () {
test('10 m down', () {
expect(freedEnergy(oneTon, 10, 0, 0, 0), oneTonTenMetersDown);
expect(freedPotential(oneTon, 10, 0), oneTonTenMetersDown);
});
test('10 m up', () {
expect(freedEnergy(oneTon, 0, 10, 0, 0), -oneTonTenMetersDown);
expect(freedPotential(oneTon, 0, 10), -oneTonTenMetersDown);
});
test('20 m down', () {
expect(freedEnergy(oneTon, 2 * 10, 0, 0, 0), 2 * oneTonTenMetersDown);
expect(potential(oneTon, 2 * 10), 2 * oneTonTenMetersDown);
});
});
group('kinetic', () {
test('10 to 0', () {
expect(freedEnergy(oneTon, 0, 0, 10, 0), tenToStop);
expect(freedKinetic(oneTon, 10, 0), tenToStop);
});
test('0 to 10', () {
expect(freedEnergy(oneTon, 0, 0, 0, 10), -tenToStop);
expect(freedKinetic(oneTon, 0, 10), -tenToStop);
});
test('20 to 0', () {
expect(freedEnergy(oneTon, 0, 0, 20, 0), 4 * tenToStop);
expect(freedKinetic(oneTon, 20, 0), 4 * tenToStop);
});
});
group('sum', () {
test('10 down & 10 to 0', () {
expect(
freedEnergy(oneTon, 10, 0, 10, 0), oneTonTenMetersDown + tenToStop);
});
test('10 up & 0 to 10', () {
expect(
freedEnergy(oneTon, 0, 10, 0, 10), -(tenToStop + oneTonTenMetersDown));
});
test('10 down & 0 to 10', () {
expect(
freedEnergy(oneTon, 10, 0, 0, 10), oneTonTenMetersDown - tenToStop);
});
test('10 up & 10 to 0', () {
expect(
freedEnergy(oneTon, 0, 10, 10, 0), tenToStop - oneTonTenMetersDown);
});
});
});
}