-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathstock_test.dart
48 lines (39 loc) · 1.57 KB
/
stock_test.dart
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
// ignore_for_file: prefer_const_constructors
import 'package:flutter_test/flutter_test.dart';
import 'package:mobile_app_flutter_redux/models/stock.dart';
void main() {
test('costBasis', () {
var stock = Stock( 'AAPL', howManyShares: 10, averagePrice: 150.0);
expect(stock.costBasis, 1500.0);
});
test('averagePriceStr', () {
var stock = Stock( 'AAPL', howManyShares: 10, averagePrice: 150.0);
expect(stock.averagePriceStr, 'US\$ 150.00');
});
test('toJson', () {
final stock = Stock( 'AAPL', howManyShares: 10, averagePrice: 150.0);
final json = stock.toJson();
expect(json, {'ticker': 'AAPL', 'howManyShares': 10, 'averagePrice': 150.0});
});
test('fromJson', () {
final json = {'ticker': 'AAPL', 'howManyShares': 10, 'averagePrice': 150.0};
var stock = Stock.fromJson(json);
expect(stock.ticker, 'AAPL');
expect(stock.howManyShares, 10);
expect(stock.averagePrice, 150.0);
});
test('Equality', () {
var stock1 = Stock( 'AAPL', howManyShares: 10, averagePrice: 150.0);
var stock2 = Stock( 'AAPL', howManyShares: 10, averagePrice: 150.0);
expect(stock1, stock2);
stock2 = Stock( 'AAPL', howManyShares: 10, averagePrice: 151.0);
expect(stock1, isNot(stock2));
});
test('HashCode', () {
var stock1 = Stock( 'AAPL', howManyShares: 10, averagePrice: 150.0);
var stock2 = Stock( 'AAPL', howManyShares: 10, averagePrice: 150.0);
expect(stock1.hashCode, stock2.hashCode);
stock2 = Stock( 'AAPL', howManyShares: 10, averagePrice: 151.0);
expect(stock1.hashCode, isNot(stock2.hashCode));
});
}