138 lines
4.2 KiB
Dart
138 lines
4.2 KiB
Dart
import 'dart:math';
|
|
|
|
import 'package:energy_bilance/models/EnergyBilanceModel.dart';
|
|
import 'package:flutter_test/flutter_test.dart';
|
|
|
|
void main() {
|
|
EnergyBilanceModel model = EnergyBilanceModel();
|
|
|
|
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);
|
|
}
|
|
|
|
group("Testing EnergyBilanceModel", () {
|
|
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
|
|
expect(0, model.potentialEnergy);
|
|
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();
|
|
});
|
|
});
|
|
}
|