Showing
2 changed files
with
9 additions
and
2 deletions
| @@ -4,7 +4,10 @@ enum TorchState { | @@ -4,7 +4,10 @@ enum TorchState { | ||
| 4 | off(0), | 4 | off(0), |
| 5 | 5 | ||
| 6 | /// The flashlight is on. | 6 | /// The flashlight is on. |
| 7 | - on(1); | 7 | + on(1), |
| 8 | + | ||
| 9 | + /// The flashlight is unavailable. | ||
| 10 | + unavailable(2); | ||
| 8 | 11 | ||
| 9 | const TorchState(this.rawValue); | 12 | const TorchState(this.rawValue); |
| 10 | 13 | ||
| @@ -14,6 +17,8 @@ enum TorchState { | @@ -14,6 +17,8 @@ enum TorchState { | ||
| 14 | return TorchState.off; | 17 | return TorchState.off; |
| 15 | case 1: | 18 | case 1: |
| 16 | return TorchState.on; | 19 | return TorchState.on; |
| 20 | + case 2: | ||
| 21 | + return TorchState.unavailable; | ||
| 17 | default: | 22 | default: |
| 18 | throw ArgumentError.value(value, 'value', 'Invalid raw value.'); | 23 | throw ArgumentError.value(value, 'value', 'Invalid raw value.'); |
| 19 | } | 24 | } |
| @@ -7,6 +7,7 @@ void main() { | @@ -7,6 +7,7 @@ void main() { | ||
| 7 | const values = <int, TorchState>{ | 7 | const values = <int, TorchState>{ |
| 8 | 0: TorchState.off, | 8 | 0: TorchState.off, |
| 9 | 1: TorchState.on, | 9 | 1: TorchState.on, |
| 10 | + 2: TorchState.unavailable, | ||
| 10 | }; | 11 | }; |
| 11 | 12 | ||
| 12 | for (final MapEntry<int, TorchState> entry in values.entries) { | 13 | for (final MapEntry<int, TorchState> entry in values.entries) { |
| @@ -18,7 +19,7 @@ void main() { | @@ -18,7 +19,7 @@ void main() { | ||
| 18 | 19 | ||
| 19 | test('invalid raw value throws argument error', () { | 20 | test('invalid raw value throws argument error', () { |
| 20 | const int negative = -1; | 21 | const int negative = -1; |
| 21 | - const int outOfRange = 2; | 22 | + const int outOfRange = 3; |
| 22 | 23 | ||
| 23 | expect(() => TorchState.fromRawValue(negative), throwsArgumentError); | 24 | expect(() => TorchState.fromRawValue(negative), throwsArgumentError); |
| 24 | expect(() => TorchState.fromRawValue(outOfRange), throwsArgumentError); | 25 | expect(() => TorchState.fromRawValue(outOfRange), throwsArgumentError); |
| @@ -28,6 +29,7 @@ void main() { | @@ -28,6 +29,7 @@ void main() { | ||
| 28 | const values = <TorchState, int>{ | 29 | const values = <TorchState, int>{ |
| 29 | TorchState.off: 0, | 30 | TorchState.off: 0, |
| 30 | TorchState.on: 1, | 31 | TorchState.on: 1, |
| 32 | + TorchState.unavailable: 2, | ||
| 31 | }; | 33 | }; |
| 32 | 34 | ||
| 33 | for (final MapEntry<TorchState, int> entry in values.entries) { | 35 | for (final MapEntry<TorchState, int> entry in values.entries) { |
-
Please register or login to post a comment