cpd_2022_energy/test/EnergyBilanceModelTest.dart

138 lines
4.2 KiB
Dart
Raw Normal View History

2022-11-08 21:37:47 +01:00
import 'dart:math';
2022-11-07 22:12:21 +01:00
import 'package:energy_bilance/models/EnergyBilanceModel.dart';
2022-11-07 22:26:47 +01:00
import 'package:flutter_test/flutter_test.dart';
2022-11-07 22:12:21 +01:00
2022-11-08 21:37:47 +01:00
void main() {
2022-11-07 22:26:47 +01:00
EnergyBilanceModel model = EnergyBilanceModel();
2022-11-08 21:37:47 +01:00
const double startHeight = 10;
const double endHeight = 20;
const double startVelocity = 0;
const double endVelocity = 100;
const double weight = 50;
const double gravity = 9.81;
const double waterHeatCapacity = 4.181; //unit: J / (g * C°)
const double ironHeatCapacity = 0.439; //unit: J / (g * C°)
resetModel() {
model.setWeight(0);
model.setStartVelocity(0);
model.setEndVelocity(0);
model.setStartHeight(0);
model.setEndHeight(0);
}
2022-11-07 22:26:47 +01:00
group("Testing EnergyBilanceModel", () {
2022-11-08 21:37:47 +01:00
test("initial calculations", () {
expect(0, model.potentialEnergy);
expect(0, model.kineticEnergy);
expect(0, model.deltaVelocity);
expect(0, model.deltaHeight);
expect(0, model.amountOfGlowingIronInKg);
expect(0, model.amountOfBoilingWaterInL);
resetModel();
});
test("deltaHeight", () {
model.setStartHeight(startHeight);
model.setEndHeight(endHeight);
expect(endHeight - startHeight, model.deltaHeight);
resetModel();
});
test("deltaVelocity", () {
model.setStartVelocity(startVelocity);
model.setEndVelocity(endVelocity);
expect(endVelocity - startVelocity, model.deltaVelocity);
resetModel();
});
test("potentialEnergy", () {
model.setStartHeight(startHeight);
model.setEndHeight(endHeight);
//without weight
expect(0, model.potentialEnergy);
model.setWeight(weight);
expect(weight * gravity * model.deltaHeight, model.potentialEnergy);
//kinetic energy should still be zero
expect(0, model.kineticEnergy);
resetModel();
});
test("kineticEnergy", () {
resetModel();
model.setStartVelocity(startVelocity);
model.setEndVelocity(endVelocity);
//without weight
expect(0, model.kineticEnergy);
model.setWeight(weight);
expect(weight * pow(model.deltaVelocity, 2) / 2, model.kineticEnergy);
//kinetic energy should still be zero
2022-11-07 22:26:47 +01:00
expect(0, model.potentialEnergy);
2022-11-08 21:37:47 +01:00
resetModel();
});
test("amountOfBoilingWaterInL", () {
model.setWeight(weight);
model.setStartVelocity(startVelocity);
model.setEndVelocity(endVelocity);
double shouldAmountWithKineticEnergy = (model.potentialEnergy + model.kineticEnergy) / waterHeatCapacity / 80 / 1000;
expect(shouldAmountWithKineticEnergy, model.amountOfBoilingWaterInL);
resetModel();
model.setWeight(weight);
model.setStartHeight(startHeight);
model.setEndHeight(endHeight);
double shouldAmountWithPotentialEnergy = (model.potentialEnergy + model.kineticEnergy) / waterHeatCapacity / 80 / 1000;
expect(shouldAmountWithPotentialEnergy, model.amountOfBoilingWaterInL);
model.setStartVelocity(startVelocity);
model.setEndVelocity(endVelocity);
double shouldAmountWithBoth = (model.potentialEnergy + model.kineticEnergy) / waterHeatCapacity / 80 / 1000;
expect(shouldAmountWithBoth, model.amountOfBoilingWaterInL);
resetModel();
});
test("amountOfGlowingIronInKg", () {
model.setWeight(weight);
model.setStartVelocity(startVelocity);
model.setEndVelocity(endVelocity);
double shouldAmountWithKineticEnergy = (model.potentialEnergy + model.kineticEnergy) / ironHeatCapacity / 680 / 1000;
expect(shouldAmountWithKineticEnergy, model.amountOfGlowingIronInKg);
resetModel();
model.setWeight(weight);
model.setStartHeight(startHeight);
model.setEndHeight(endHeight);
double shouldAmountWithPotentialEnergy = (model.potentialEnergy + model.kineticEnergy) / ironHeatCapacity / 680 / 1000;
expect(shouldAmountWithPotentialEnergy, model.amountOfGlowingIronInKg);
model.setStartVelocity(startVelocity);
model.setEndVelocity(endVelocity);
double shouldAmountWithBoth = (model.potentialEnergy + model.kineticEnergy) / ironHeatCapacity / 680 / 1000;
expect(shouldAmountWithBoth, model.amountOfGlowingIronInKg);
resetModel();
2022-11-07 22:26:47 +01:00
});
});
}