-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
17 changed files
with
155 additions
and
103 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
1.9.2 | ||
1.9.3 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,22 +1,32 @@ | ||
import 'package:sourdoc/methods/convert_temperature_unit.dart'; | ||
import 'package:sourdoc/methods/temperature_unit_helpers.dart'; | ||
|
||
// Default initial values | ||
const TemperatureUnit defaultTemperatureUnit = TemperatureUnit.celsius; | ||
final String defaultTemperatureUnitValue = | ||
temperatureUnitMap[defaultTemperatureUnit]!.unit; | ||
const Map<TemperatureUnit, String> defaultTemperatureMap = { | ||
TemperatureUnit.celsius: '22', | ||
TemperatureUnit.farenheit: '72' | ||
}; | ||
final String defaultTemperatureUnitSymbol = | ||
getTemperatureUnitSymbol(defaultTemperatureUnit); | ||
const String defaultTotalWeight = '700'; | ||
const String defaultHydration = '70'; | ||
const String defaultSaltLevel = '2'; | ||
String getDefaultTemperature(TemperatureUnit temperatureUnit) { | ||
if (temperatureUnit == TemperatureUnit.celsius) { | ||
return '22'; | ||
} | ||
if (temperatureUnit == TemperatureUnit.farenheit) { | ||
return '72'; | ||
} | ||
throw ArgumentError.value('temperatureUnit'); | ||
} | ||
|
||
// Maximum values | ||
const Map<TemperatureUnit, double> maxValueTemperatureMap = { | ||
TemperatureUnit.celsius: 40, | ||
TemperatureUnit.farenheit: 104 | ||
}; | ||
const double maxValueTotalWeight = 9999; | ||
const double maxValueHydration = 99; | ||
const double maxValueSaltLevel = 10; | ||
double getMaxValueTemperature(TemperatureUnit temperatureUnit) { | ||
if (temperatureUnit == TemperatureUnit.celsius) { | ||
return 40; | ||
} | ||
if (temperatureUnit == TemperatureUnit.farenheit) { | ||
return 104; | ||
} | ||
throw ArgumentError.value('temperatureUnit'); | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
import 'package:sourdoc/constants/locale.dart' as locale; | ||
|
||
enum TemperatureUnit { celsius, farenheit } | ||
|
||
class TemperatureUnitDescriptor { | ||
TemperatureUnitDescriptor( | ||
{required this.name, required this.symbol, required this.description}); | ||
|
||
final TemperatureUnit name; | ||
final String symbol; | ||
final String description; | ||
} | ||
|
||
final Set<TemperatureUnitDescriptor> temperatureUnitSet = { | ||
TemperatureUnitDescriptor( | ||
name: TemperatureUnit.celsius, | ||
symbol: locale.unitDegreesCelsius, | ||
description: locale.degreesCelsius), | ||
TemperatureUnitDescriptor( | ||
name: TemperatureUnit.farenheit, | ||
symbol: locale.unitDegreesFarenheit, | ||
description: locale.degreesFarenheit) | ||
}; | ||
|
||
String getTemperatureUnitSymbol(TemperatureUnit temperatureUnit) { | ||
return temperatureUnitSet | ||
.singleWhere((unit) => unit.name == temperatureUnit) | ||
.symbol; | ||
} | ||
|
||
TemperatureUnit getTemperatureUnitName(String symbol) { | ||
return temperatureUnitSet.singleWhere((unit) => unit.symbol == symbol).name; | ||
} | ||
|
||
double convertTemperatureToUnit(double temperature, TemperatureUnit toUnit) { | ||
if (toUnit == TemperatureUnit.celsius) { | ||
return 5 / 9 * (temperature - 32); | ||
} | ||
if (toUnit == TemperatureUnit.farenheit) { | ||
return 9 / 5 * temperature + 32; | ||
} | ||
throw ArgumentError.value('toUnit'); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
import 'package:flutter_test/flutter_test.dart'; | ||
import 'package:sourdoc/constants/locale.dart' as locale; | ||
import 'package:sourdoc/methods/temperature_unit_helpers.dart'; | ||
|
||
void main() { | ||
group('temperatureUnitSet', () { | ||
test('should have the correct lenght', () { | ||
expect(temperatureUnitSet.length, 2); | ||
}); | ||
|
||
test('should have the correct ordered keys', () { | ||
expect( | ||
temperatureUnitSet | ||
.singleWhere((unit) => unit.name == TemperatureUnit.celsius), | ||
isInstanceOf<TemperatureUnitDescriptor>()); | ||
expect( | ||
temperatureUnitSet | ||
.singleWhere((unit) => unit.name == TemperatureUnit.farenheit), | ||
isInstanceOf<TemperatureUnitDescriptor>()); | ||
}); | ||
}); | ||
|
||
group('getTemperatureUnitSymbol', () { | ||
test('should get the unit\'s symbol from its name', () { | ||
expect(getTemperatureUnitSymbol(TemperatureUnit.celsius), | ||
locale.unitDegreesCelsius); | ||
expect(getTemperatureUnitSymbol(TemperatureUnit.farenheit), | ||
locale.unitDegreesFarenheit); | ||
}); | ||
}); | ||
|
||
group('getTemperatureUnitSymbol', () { | ||
test('should get the unit\'s name from its symbol', () { | ||
expect(getTemperatureUnitName(locale.unitDegreesCelsius), | ||
TemperatureUnit.celsius); | ||
expect(getTemperatureUnitName(locale.unitDegreesFarenheit), | ||
TemperatureUnit.farenheit); | ||
}); | ||
}); | ||
|
||
group('convertTemperatureUnit', () { | ||
test('should convert farenheit to celsius', () { | ||
expect(convertTemperatureToUnit(20, TemperatureUnit.farenheit), 68); | ||
}); | ||
|
||
test('should convert celsius to farenheit', () { | ||
expect(convertTemperatureToUnit(68, TemperatureUnit.celsius), 20); | ||
}); | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.