Files
flame/packages/flame_noise/test/noise_effect_controller_test.dart
Luan Nico 2fd84c846f feat!: Update flame_noise to use latest version of fast_noise (#3015)
Update flame_noise to use the latest version of fast_noise, basically
replacing the Perlin-specific effect controller with a generic
`NoiseEffectController` that can take in any noise class (leveraging the
new Noise2 interface).

Just update from `PerlinNoiseEffectController` to
`NoiseEffectController` and provide the noise/parameters you want
directly into the `noise` field.

---------

Co-authored-by: Lukas Klingsbo <me@lukas.fyi>
2024-02-04 16:37:54 +01:00

54 lines
1.4 KiB
Dart

import 'package:flame_noise/flame_noise.dart';
import 'package:flame_test/flame_test.dart';
import 'package:flutter/animation.dart';
import 'package:test/test.dart';
void main() {
group('PerlinNoiseEffectController', () {
test('general properties', () {
final ec = NoiseEffectController(
duration: 1,
noise: PerlinNoise(frequency: 12),
);
expect(ec.duration, 1.0);
expect(ec.taperingCurve, Curves.easeInOutCubic);
expect(ec.started, true);
expect(ec.completed, false);
expect(ec.progress, 0);
expect(ec.isRandom, false);
});
test('progression', () {
final ec = NoiseEffectController(
duration: 1,
noise: PerlinNoise(frequency: 0.05),
);
final observed = <double>[];
for (var t = 0.0; t < 1.0; t += 0.1) {
observed.add(ec.progress);
ec.advance(0.1);
}
expect(observed, [
0.051042312500000006,
0.04563924284681871,
0.03940642509655703,
0.03206554217595054,
0.02339568569800122,
0.013401536786893568,
0.005727844335713328,
0.002079860116340368,
0.000573751223192571,
0.00008544214797850498,
3.6806334242205264e-9,
]);
});
test('errors', () {
expect(
() => NoiseEffectController(duration: -1),
failsAssert('Duration cannot be negative: -1.0'),
);
});
});
}