|
|
|
@ -4,16 +4,19 @@ import 'package:test/test.dart';
|
|
|
|
|
enum FruitSort { |
|
|
|
|
alphabetical, |
|
|
|
|
count, |
|
|
|
|
price, |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
class Fruit { |
|
|
|
|
Fruit( |
|
|
|
|
const Fruit( |
|
|
|
|
this.name, |
|
|
|
|
this.count, |
|
|
|
|
); |
|
|
|
|
this.count, [ |
|
|
|
|
this.price, |
|
|
|
|
]); |
|
|
|
|
|
|
|
|
|
final String name; |
|
|
|
|
final int count; |
|
|
|
|
final int? price; |
|
|
|
|
|
|
|
|
|
@override |
|
|
|
|
String toString() => 'Fruit(name: $name, count: $count)'; |
|
|
|
@ -24,21 +27,30 @@ void main() {
|
|
|
|
|
{ |
|
|
|
|
FruitSort.alphabetical: (final fruit) => fruit.name.toLowerCase(), |
|
|
|
|
FruitSort.count: (final fruit) => fruit.count, |
|
|
|
|
FruitSort.price: (final fruit) => fruit.price!, |
|
|
|
|
}, |
|
|
|
|
{ |
|
|
|
|
FruitSort.alphabetical: Box(FruitSort.count, SortBoxOrder.ascending), |
|
|
|
|
FruitSort.count: Box(FruitSort.alphabetical, SortBoxOrder.ascending), |
|
|
|
|
FruitSort.alphabetical: { |
|
|
|
|
Box(FruitSort.count, SortBoxOrder.ascending), |
|
|
|
|
}, |
|
|
|
|
FruitSort.count: { |
|
|
|
|
Box(FruitSort.alphabetical, SortBoxOrder.ascending), |
|
|
|
|
}, |
|
|
|
|
FruitSort.price: { |
|
|
|
|
Box(FruitSort.alphabetical, SortBoxOrder.descending), |
|
|
|
|
Box(FruitSort.count, SortBoxOrder.ascending), |
|
|
|
|
}, |
|
|
|
|
}, |
|
|
|
|
); |
|
|
|
|
|
|
|
|
|
group('Primary', () { |
|
|
|
|
test('Alphabetical', () { |
|
|
|
|
final fruits = [ |
|
|
|
|
Fruit('Apple', 1), |
|
|
|
|
Fruit('Banana', 2), |
|
|
|
|
Fruit('Apple', 3), |
|
|
|
|
Fruit('Banana', 4), |
|
|
|
|
Fruit('Apple', 5), |
|
|
|
|
const Fruit('Apple', 1), |
|
|
|
|
const Fruit('Banana', 2), |
|
|
|
|
const Fruit('Apple', 3), |
|
|
|
|
const Fruit('Banana', 4), |
|
|
|
|
const Fruit('Apple', 5), |
|
|
|
|
]; |
|
|
|
|
final sorted = sortBox.sort(fruits, Box(FruitSort.alphabetical, SortBoxOrder.ascending)); |
|
|
|
|
|
|
|
|
@ -52,11 +64,11 @@ void main() {
|
|
|
|
|
|
|
|
|
|
test('Count', () { |
|
|
|
|
final fruits = [ |
|
|
|
|
Fruit('Apple', 1), |
|
|
|
|
Fruit('Banana', 5), |
|
|
|
|
Fruit('Apple', 4), |
|
|
|
|
Fruit('Banana', 2), |
|
|
|
|
Fruit('Apple', 3), |
|
|
|
|
const Fruit('Apple', 1), |
|
|
|
|
const Fruit('Banana', 5), |
|
|
|
|
const Fruit('Apple', 4), |
|
|
|
|
const Fruit('Banana', 2), |
|
|
|
|
const Fruit('Apple', 3), |
|
|
|
|
]; |
|
|
|
|
final sorted = sortBox.sort(fruits, Box(FruitSort.count, SortBoxOrder.ascending)); |
|
|
|
|
|
|
|
|
@ -73,11 +85,11 @@ void main() {
|
|
|
|
|
group('Secondary', () { |
|
|
|
|
test('Alphabetical', () { |
|
|
|
|
final fruits = [ |
|
|
|
|
Fruit('Apple', 1), |
|
|
|
|
Fruit('Banana', 2), |
|
|
|
|
Fruit('Apple', 2), |
|
|
|
|
Fruit('Banana', 1), |
|
|
|
|
Fruit('Apple', 2), |
|
|
|
|
const Fruit('Apple', 1), |
|
|
|
|
const Fruit('Banana', 2), |
|
|
|
|
const Fruit('Apple', 2), |
|
|
|
|
const Fruit('Banana', 1), |
|
|
|
|
const Fruit('Apple', 2), |
|
|
|
|
]; |
|
|
|
|
final sorted = sortBox.sort(fruits, Box(FruitSort.count, SortBoxOrder.ascending)); |
|
|
|
|
|
|
|
|
@ -94,11 +106,11 @@ void main() {
|
|
|
|
|
|
|
|
|
|
test('Count', () { |
|
|
|
|
final fruits = [ |
|
|
|
|
Fruit('Apple', 3), |
|
|
|
|
Fruit('Banana', 4), |
|
|
|
|
Fruit('Apple', 1), |
|
|
|
|
Fruit('Banana', 2), |
|
|
|
|
Fruit('Apple', 5), |
|
|
|
|
const Fruit('Apple', 3), |
|
|
|
|
const Fruit('Banana', 4), |
|
|
|
|
const Fruit('Apple', 1), |
|
|
|
|
const Fruit('Banana', 2), |
|
|
|
|
const Fruit('Apple', 5), |
|
|
|
|
]; |
|
|
|
|
final sorted = sortBox.sort(fruits, Box(FruitSort.alphabetical, SortBoxOrder.ascending)); |
|
|
|
|
|
|
|
|
@ -116,11 +128,11 @@ void main() {
|
|
|
|
|
|
|
|
|
|
test('Primary all equal', () { |
|
|
|
|
final fruits = [ |
|
|
|
|
Fruit('Coconut', 1), |
|
|
|
|
Fruit('Banana', 1), |
|
|
|
|
Fruit('Apple', 1), |
|
|
|
|
Fruit('Elderberry', 1), |
|
|
|
|
Fruit('Damson', 1), |
|
|
|
|
const Fruit('Coconut', 1), |
|
|
|
|
const Fruit('Banana', 1), |
|
|
|
|
const Fruit('Apple', 1), |
|
|
|
|
const Fruit('Elderberry', 1), |
|
|
|
|
const Fruit('Damson', 1), |
|
|
|
|
]; |
|
|
|
|
final sorted = sortBox.sort(fruits, Box(FruitSort.count, SortBoxOrder.ascending)); |
|
|
|
|
|
|
|
|
@ -130,4 +142,32 @@ void main() {
|
|
|
|
|
} |
|
|
|
|
}); |
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
group('Third', () { |
|
|
|
|
test('Count', () { |
|
|
|
|
final fruits = [ |
|
|
|
|
const Fruit('Apple', 1, 3), |
|
|
|
|
const Fruit('Banana', 2, 2), |
|
|
|
|
const Fruit('Apple', 2, 0), |
|
|
|
|
const Fruit('Banana', 1, 3), |
|
|
|
|
const Fruit('Apple', 2, 3), |
|
|
|
|
]; |
|
|
|
|
final sorted = sortBox.sort(fruits, Box(FruitSort.price, SortBoxOrder.ascending)); |
|
|
|
|
|
|
|
|
|
final price = [0, 2, 3, 3, 3]; |
|
|
|
|
for (var i = 0; i < 5; i++) { |
|
|
|
|
expect(sorted[i].price, price[i]); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
final names = ['Apple', 'Banana', 'Banana', 'Apple', 'Apple']; |
|
|
|
|
for (var i = 0; i < 5; i++) { |
|
|
|
|
expect(sorted[i].name, names[i]); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
final counts = [2, 2, 1, 1, 2]; |
|
|
|
|
for (var i = 0; i < 5; i++) { |
|
|
|
|
expect(sorted[i].count, counts[i]); |
|
|
|
|
} |
|
|
|
|
}); |
|
|
|
|
}); |
|
|
|
|
} |
|
|
|
|