modify generateChartColors() test cases to use _iterator_ instead of toList() since it's been used in the original code.

This commit is contained in:
Bassam A
2024-02-03 11:55:33 +03:00
parent 1764147c18
commit 36f9d1651e
2 changed files with 61 additions and 18 deletions

View File

@@ -3,34 +3,76 @@ import 'package:wger/helpers/colors.dart';
void main() {
group('generateChartColors', () {
test('should generate 3 colors for 3 items', () {
final colors = generateChartColors(3).toList();
expect(colors, LIST_OF_COLORS3);
test('should generate 3 colors for 3 items using iterator', () {
final iterator = generateChartColors(3).iterator;
final expectedColors = LIST_OF_COLORS3.iterator;
while (iterator.moveNext() && expectedColors.moveNext()) {
expect(iterator.current, equals(expectedColors.current));
}
expect(iterator.moveNext(), isFalse);
expect(expectedColors.moveNext(), isFalse);
});
test('should generate 5 colors for 5 items', () {
final colors = generateChartColors(5).toList();
expect(colors, LIST_OF_COLORS5);
test('should generate 5 colors for 5 items using iterator', () {
final iterator = generateChartColors(5).iterator;
final expectedColors = LIST_OF_COLORS5.iterator;
while (iterator.moveNext() && expectedColors.moveNext()) {
expect(iterator.current, equals(expectedColors.current));
}
expect(iterator.moveNext(), isFalse);
expect(expectedColors.moveNext(), isFalse);
});
test('should generate 8 colors for 8 items', () {
final colors = generateChartColors(8).toList();
expect(colors, LIST_OF_COLORS8);
test('should generate 8 colors for 8 items using iterator', () {
final iterator = generateChartColors(8).iterator;
final expectedColors = LIST_OF_COLORS8.iterator;
while (iterator.moveNext() && expectedColors.moveNext()) {
expect(iterator.current, equals(expectedColors.current));
}
expect(iterator.moveNext(), isFalse);
expect(expectedColors.moveNext(), isFalse);
});
test('should generate 8 colors for more than 8 items', () {
final colors = generateChartColors(10).toList();
expect(colors, LIST_OF_COLORS8);
test('should generate 8 colors for more than 8 items using iterator', () {
final iterator = generateChartColors(10).iterator;
final expectedColors = LIST_OF_COLORS8.iterator;
while (iterator.moveNext() && expectedColors.moveNext()) {
expect(iterator.current, equals(expectedColors.current));
}
expect(iterator.moveNext(), isFalse);
expect(expectedColors.moveNext(), isFalse);
});
test('should generate 8 colors for 0 items', () {
final colors = generateChartColors(0).toList();
expect(colors, LIST_OF_COLORS3);
test('should generate 8 colors for 0 items using iterator', () {
final iterator = generateChartColors(0).iterator;
final expectedColors = LIST_OF_COLORS3.iterator;
while (iterator.moveNext() && expectedColors.moveNext()) {
expect(iterator.current, equals(expectedColors.current));
}
expect(iterator.moveNext(), isFalse);
expect(expectedColors.moveNext(), isFalse);
});
test('should generate 8 colors for negative items', () {
final colors = generateChartColors(-5).toList();
expect(colors, LIST_OF_COLORS3);
test('should generate 8 colors for negative items using iterator', () {
final iterator = generateChartColors(-5).iterator;
final expectedColors = LIST_OF_COLORS3.iterator;
while (iterator.moveNext() && expectedColors.moveNext()) {
expect(iterator.current, equals(expectedColors.current));
}
expect(iterator.moveNext(), isFalse);
expect(expectedColors.moveNext(), isFalse);
});
});
}