OLD | NEW |
(Empty) | |
| 1 library charted.test.chaintransform; |
| 2 |
| 3 import 'package:charted/charts/charts.dart'; |
| 4 import 'package:charted/core/utils.dart'; |
| 5 import 'package:unittest/unittest.dart'; |
| 6 import 'package:observe/observe.dart'; |
| 7 |
| 8 main() { |
| 9 List COLUMNS = [ |
| 10 new ChartColumnSpec(label:'Continent', type:ChartColumnSpec.TYPE_STRING), |
| 11 new ChartColumnSpec(label:'Country', type:ChartColumnSpec.TYPE_STRING), |
| 12 new ChartColumnSpec(label:'City', type:ChartColumnSpec.TYPE_STRING), |
| 13 new ChartColumnSpec(label:'Stats1'), |
| 14 new ChartColumnSpec(label:'Stats2'), |
| 15 new ChartColumnSpec(label:'Stats3') |
| 16 ]; |
| 17 |
| 18 const List DATA = const [ |
| 19 const['America', 'USA', 'LA', 4.51, 7, 1000], |
| 20 const['America', 'USA', 'SF', 9.50, 50, 2000], |
| 21 const['Asia', 'Japan', 'Tokyo', 1.50, 99, 2000], |
| 22 const['Asia', 'Japan', 'Kyoto', 5.10, 66, 4000], |
| 23 const['Asia', 'Taiwan', 'Taipei', 3.50, 127, 1337], |
| 24 const['Asia', 'Japan', 'Osaka', 4.50, 19, 2000], |
| 25 const['Asia', 'Taiwan', 'Tainan', 1.50, 10, 100], |
| 26 const['Europe', 'France', 'Nice', 2.50, 29, 6000], |
| 27 const['Europe', 'France', 'Paris', 6.50, 129, 3000], |
| 28 const['Europe', 'Germany', 'Berlin', 10.99, 999, 10000], |
| 29 const['Europe', 'England', 'London', 2.50, 10, 3000], |
| 30 const['America', 'USA', 'NY', 3.50, 17, 4000], |
| 31 const['America', 'Brazil', 'Brasilia', 1.50, 27, 6000], |
| 32 const['America', 'Argentina', 'Buenos Aires', 5.50, 37, 2000], |
| 33 const['America', 'Brazil', 'Rio de Janeiro', 2.50, 52, 3000], |
| 34 ]; |
| 35 |
| 36 ChartData inputData = new ChartData(COLUMNS, DATA); |
| 37 |
| 38 test('Filter out sum aggregated rows whose stats2 is above 1000', () { |
| 39 AggregationTransformer aggrTransformer = new AggregationTransformer( |
| 40 [0, 1, 2], [3, 4, 5]); |
| 41 FilterDefinition fd = new FilterDefinition(4, (value) => (value <= 1000)); |
| 42 FilterTransformer filterTransformer = new FilterTransformer([fd]); |
| 43 ChartData result = filterTransformer.transform( |
| 44 aggrTransformer.transform(inputData)); |
| 45 // Expected data: |
| 46 // [America, , , 27.0, 190.0, 18000.0] |
| 47 // [Asia, , , 16.1, 321.0, 9437.0] |
| 48 // [Europe, , , 22.49, 1167.0, 22000.0] -- Filtered out |
| 49 |
| 50 // [America, , , 27.0, 190.0, 18000.0] |
| 51 expect(result.rows.elementAt(0).elementAt(3), closeTo(27.01, EPSILON)); |
| 52 expect(result.rows.elementAt(0).elementAt(4), equals(190)); |
| 53 expect(result.rows.elementAt(0).elementAt(5), equals(18000)); |
| 54 |
| 55 // [Asia, , , 16.1, 321.0, 9437.0] |
| 56 expect(result.rows.elementAt(1).elementAt(3), closeTo(16.1, EPSILON)); |
| 57 expect(result.rows.elementAt(1).elementAt(4), equals(321)); |
| 58 expect(result.rows.elementAt(1).elementAt(5), equals(9437)); |
| 59 |
| 60 }); |
| 61 |
| 62 test('Filter out rows whose stats3 is below 4000', () { |
| 63 FilterDefinition fd = new FilterDefinition(5, (value) => (value >= 4000)); |
| 64 FilterTransformer transformer = new FilterTransformer([fd]); |
| 65 ChartData result = transformer.transform(inputData); |
| 66 // Expected data: |
| 67 // ['Asia', 'Japan', 'Kyoto', 5.10, 66, 4000], |
| 68 // ['Europe', 'France', 'Nice', 2.50, 29, 6000], |
| 69 // ['Europe', 'Germany', 'Berlin', 10.99, 999, 10000], |
| 70 // ['America', 'USA', 'NY', 3.50, 17, 4000], |
| 71 // ['America', 'Brazil', 'Brasilia', 1.50, 27, 6000], |
| 72 |
| 73 // ['Asia', 'Japan', 'Kyoto', 5.10, 66, 4000] |
| 74 expect(result.rows.elementAt(0).elementAt(0), equals('Asia')); |
| 75 expect(result.rows.elementAt(0).elementAt(1), equals('Japan')); |
| 76 expect(result.rows.elementAt(0).elementAt(2), equals('Kyoto')); |
| 77 expect(result.rows.elementAt(0).elementAt(3), equals(5.10)); |
| 78 expect(result.rows.elementAt(0).elementAt(4), equals(66)); |
| 79 expect(result.rows.elementAt(0).elementAt(5), equals(4000)); |
| 80 |
| 81 // ['Europe', 'Germany', 'Berlin', 10.99, 999, 10000] |
| 82 expect(result.rows.elementAt(2).elementAt(0), equals('Europe')); |
| 83 expect(result.rows.elementAt(2).elementAt(1), equals('Germany')); |
| 84 expect(result.rows.elementAt(2).elementAt(2), equals('Berlin')); |
| 85 expect(result.rows.elementAt(2).elementAt(3), equals(10.99)); |
| 86 expect(result.rows.elementAt(2).elementAt(4), equals(999)); |
| 87 expect(result.rows.elementAt(2).elementAt(5), equals(10000)); |
| 88 |
| 89 // ['America', 'Brazil', 'Brasilia', 1.50, 27, 6000], |
| 90 expect(result.rows.elementAt(4).elementAt(0), equals('America')); |
| 91 expect(result.rows.elementAt(4).elementAt(1), equals('Brazil')); |
| 92 expect(result.rows.elementAt(4).elementAt(2), equals('Brasilia')); |
| 93 expect(result.rows.elementAt(4).elementAt(3), equals(1.5)); |
| 94 expect(result.rows.elementAt(4).elementAt(4), equals(27)); |
| 95 expect(result.rows.elementAt(4).elementAt(5), equals(6000)); |
| 96 }); |
| 97 |
| 98 test('Grouping by country-continent-city with less fact columns, the ' + |
| 99 'filter out rows whose stats3 (column4) is less than 8000', () { |
| 100 AggregationTransformer aggrTransformer = new AggregationTransformer( |
| 101 [1, 2, 0], [5, 3]); |
| 102 |
| 103 ChartData aggrResult = aggrTransformer.transform(inputData); |
| 104 // Result at this point: |
| 105 // [Argentina, , , 2000.0, 5.50] |
| 106 // [Brazil, , , 9000.0, 4.00] |
| 107 // [England, , , 3000.0, 2.50] |
| 108 // [France, , , 9000.0, 9.00] |
| 109 // ... |
| 110 |
| 111 FilterDefinition fd = new FilterDefinition(3, (value) => (value >= 8000)); |
| 112 FilterTransformer transformer = new FilterTransformer([fd]); |
| 113 (aggrResult as Observable).deliverChanges(); |
| 114 ChartData result = transformer.transform(aggrResult); |
| 115 |
| 116 // Result at this point: |
| 117 // [Brazil, , , 9000.0, 4.00] |
| 118 // [France, , , 9000.0, 9.00] |
| 119 // ... |
| 120 |
| 121 // Brazil |
| 122 expect(result.rows.elementAt(0).elementAt(3), equals(9000)); |
| 123 expect(result.rows.elementAt(0).elementAt(4), closeTo(4, EPSILON)); |
| 124 |
| 125 // France |
| 126 expect(result.rows.elementAt(1).elementAt(3), equals(9000)); |
| 127 expect(result.rows.elementAt(1).elementAt(4), closeTo(9, EPSILON)); |
| 128 }); |
| 129 |
| 130 } |
OLD | NEW |