Skip to content

Commit

Permalink
Add Angstroms Length-Converter option (microsoft#2229)
Browse files Browse the repository at this point in the history
* Add Length_Angstrom as a new unit constant

Adds Angstrom as a length unit to the list of unit constants in UnitConverterDataConstants.h file.

* Add Angstrom unit to Length units in UnitConverterDataLoader.cpp

Adds the Angstrom unit of length to the list of length units in UnitConverterDataLoader.cpp and its conversion data is added to the GetConversionData() function.

It is assigned the value of 15.

* Add Angstrom as a Unit of Length

Adds new data entries to Resources.resw for unit abbreviation of Angstrom, and the unit name for Angstrom.

* Add conversion data "Meters-Angstroms" in Test.resw

Adds new data entry for "Meters-Angstroms" to Test.resw file

* Changes order of units of Length to add Angstroms

This commit changes the order of the units of length so that Angstrom is before Nanometers.
Increments orders of all other units by 1 and sets order of Angstroms to 1.

* Fixes 'TestStandardUnitConverterAndDateViewModels' test case failing

This commit fixes the "TestStandardUnitConverterAndDateViewModels" failing by introducing a new resource entry to the Test.resw file.

These changes needed to be made because adding the new unit changed the order of units, hence the test case expected a different value, since it was converting other units.
  • Loading branch information
DevBoiAgru authored Sep 24, 2024
1 parent 88c22ca commit ff16a72
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 18 deletions.
5 changes: 3 additions & 2 deletions src/CalcViewModel/DataLoaders/UnitConverterDataConstants.h
Original file line number Diff line number Diff line change
Expand Up @@ -165,8 +165,9 @@ namespace CalculatorApp
Data_Zetabytes = UnitStart + 164,
Area_Pyeong = UnitStart + 165,
Energy_Kilowatthour = UnitStart + 166,
Data_Nibble = UnitStart + 167,
UnitEnd = Data_Nibble
Data_Nibble = UnitStart + 167,
Length_Angstrom = UnitStart + 168,
UnitEnd = Length_Angstrom
};
}
}
31 changes: 17 additions & 14 deletions src/CalcViewModel/DataLoaders/UnitConverterDataLoader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -400,53 +400,55 @@ void UnitConverterDataLoader::GetUnits(_In_ unordered_map<ViewMode, vector<Order
unitMap.emplace(ViewMode::Energy, energyUnits);

vector<OrderedUnit> lengthUnits;
lengthUnits.push_back(OrderedUnit{
UnitConverterUnits::Length_Angstrom, GetLocalizedStringName(L"UnitName_Angstrom"), GetLocalizedStringName(L"UnitAbbreviation_Angstrom"), 1 });
lengthUnits.push_back(OrderedUnit{ UnitConverterUnits::Length_Centimeter,
GetLocalizedStringName(L"UnitName_Centimeter"),
GetLocalizedStringName(L"UnitAbbreviation_Centimeter"),
4,
5,
useUSCustomary,
useSI,
false });
lengthUnits.push_back(
OrderedUnit{ UnitConverterUnits::Length_Foot, GetLocalizedStringName(L"UnitName_Foot"), GetLocalizedStringName(L"UnitAbbreviation_Foot"), 8 });
OrderedUnit{ UnitConverterUnits::Length_Foot, GetLocalizedStringName(L"UnitName_Foot"), GetLocalizedStringName(L"UnitAbbreviation_Foot"), 9 });
lengthUnits.push_back(OrderedUnit{ UnitConverterUnits::Length_Inch,
GetLocalizedStringName(L"UnitName_Inch"),
GetLocalizedStringName(L"UnitAbbreviation_Inch"),
7,
8,
useSI,
useUSCustomary,
false });
lengthUnits.push_back(OrderedUnit{
UnitConverterUnits::Length_Kilometer, GetLocalizedStringName(L"UnitName_Kilometer"), GetLocalizedStringName(L"UnitAbbreviation_Kilometer"), 6 });
UnitConverterUnits::Length_Kilometer, GetLocalizedStringName(L"UnitName_Kilometer"), GetLocalizedStringName(L"UnitAbbreviation_Kilometer"), 7 });
lengthUnits.push_back(
OrderedUnit{ UnitConverterUnits::Length_Meter, GetLocalizedStringName(L"UnitName_Meter"), GetLocalizedStringName(L"UnitAbbreviation_Meter"), 5 });
OrderedUnit{ UnitConverterUnits::Length_Meter, GetLocalizedStringName(L"UnitName_Meter"), GetLocalizedStringName(L"UnitAbbreviation_Meter"), 6 });
lengthUnits.push_back(
OrderedUnit{ UnitConverterUnits::Length_Micron, GetLocalizedStringName(L"UnitName_Micron"), GetLocalizedStringName(L"UnitAbbreviation_Micron"), 2 });
OrderedUnit{ UnitConverterUnits::Length_Micron, GetLocalizedStringName(L"UnitName_Micron"), GetLocalizedStringName(L"UnitAbbreviation_Micron"), 3 });
lengthUnits.push_back(
OrderedUnit{ UnitConverterUnits::Length_Mile, GetLocalizedStringName(L"UnitName_Mile"), GetLocalizedStringName(L"UnitAbbreviation_Mile"), 10 });
OrderedUnit{ UnitConverterUnits::Length_Mile, GetLocalizedStringName(L"UnitName_Mile"), GetLocalizedStringName(L"UnitAbbreviation_Mile"), 11 });
lengthUnits.push_back(OrderedUnit{
UnitConverterUnits::Length_Millimeter, GetLocalizedStringName(L"UnitName_Millimeter"), GetLocalizedStringName(L"UnitAbbreviation_Millimeter"), 3 });
UnitConverterUnits::Length_Millimeter, GetLocalizedStringName(L"UnitName_Millimeter"), GetLocalizedStringName(L"UnitAbbreviation_Millimeter"), 4 });
lengthUnits.push_back(OrderedUnit{
UnitConverterUnits::Length_Nanometer, GetLocalizedStringName(L"UnitName_Nanometer"), GetLocalizedStringName(L"UnitAbbreviation_Nanometer"), 1 });
UnitConverterUnits::Length_Nanometer, GetLocalizedStringName(L"UnitName_Nanometer"), GetLocalizedStringName(L"UnitAbbreviation_Nanometer"), 2 });
lengthUnits.push_back(OrderedUnit{ UnitConverterUnits::Length_NauticalMile,
GetLocalizedStringName(L"UnitName_NauticalMile"),
GetLocalizedStringName(L"UnitAbbreviation_NauticalMile"),
11 });
12 });
lengthUnits.push_back(
OrderedUnit{ UnitConverterUnits::Length_Yard, GetLocalizedStringName(L"UnitName_Yard"), GetLocalizedStringName(L"UnitAbbreviation_Yard"), 9 });
OrderedUnit{ UnitConverterUnits::Length_Yard, GetLocalizedStringName(L"UnitName_Yard"), GetLocalizedStringName(L"UnitAbbreviation_Yard"), 10 });
lengthUnits.push_back(OrderedUnit{ UnitConverterUnits::Length_Paperclip,
GetLocalizedStringName(L"UnitName_Paperclip"),
GetLocalizedStringName(L"UnitAbbreviation_Paperclip"),
12,
13,
false,
false,
true });
lengthUnits.push_back(OrderedUnit{
UnitConverterUnits::Length_Hand, GetLocalizedStringName(L"UnitName_Hand"), GetLocalizedStringName(L"UnitAbbreviation_Hand"), 13, false, false, true });
UnitConverterUnits::Length_Hand, GetLocalizedStringName(L"UnitName_Hand"), GetLocalizedStringName(L"UnitAbbreviation_Hand"), 14, false, false, true });
lengthUnits.push_back(OrderedUnit{ UnitConverterUnits::Length_JumboJet,
GetLocalizedStringName(L"UnitName_JumboJet"),
GetLocalizedStringName(L"UnitAbbreviation_JumboJet"),
14,
15,
false,
false,
true });
Expand Down Expand Up @@ -855,6 +857,7 @@ void UnitConverterDataLoader::GetConversionData(_In_ unordered_map<ViewMode, uno
{ ViewMode::Length, UnitConverterUnits::Length_Micron, 0.000001 },
{ ViewMode::Length, UnitConverterUnits::Length_Millimeter, 0.001 },
{ ViewMode::Length, UnitConverterUnits::Length_Nanometer, 0.000000001 },
{ ViewMode::Length, UnitConverterUnits::Length_Angstrom, 0.0000000001 },
{ ViewMode::Length, UnitConverterUnits::Length_Centimeter, 0.01 },
{ ViewMode::Length, UnitConverterUnits::Length_Meter, 1 },
{ ViewMode::Length, UnitConverterUnits::Length_Kilometer, 1000 },
Expand Down
8 changes: 8 additions & 0 deletions src/Calculator/Resources/en-US/Resources.resw
Original file line number Diff line number Diff line change
Expand Up @@ -1665,6 +1665,10 @@
<value>cup (US)</value>
<comment>An abbreviation for a measurement unit of volume</comment>
</data>
<data name="UnitAbbreviation_Angstrom" xml:space="preserve">
<value>A</value>
<comment>An abbreviation for a measurement unit of length</comment>
</data>
<data name="UnitAbbreviation_Acre" xml:space="preserve">
<value>ac</value>
<comment>An abbreviation for a measurement unit of volume</comment>
Expand Down Expand Up @@ -2241,6 +2245,10 @@
<value>Nanometers</value>
<comment>A measurement unit for length. (Please choose the most appropriate plural form to fit any number between 0 and 999,999,999,999,999)</comment>
</data>
<data name="UnitName_Angstrom" xml:space="preserve">
<value>Angstroms</value>
<comment>A measurement unit for length. (Please choose the most appropriate plural form to fit any number between 0 and 999,999,999,999,999)</comment>
</data>
<data name="UnitName_NauticalMile" xml:space="preserve">
<value>Nautical miles</value>
<comment>A measurement unit for length. (Please choose the most appropriate plural form to fit any number between 0 and 999,999,999,999,999)</comment>
Expand Down
7 changes: 5 additions & 2 deletions src/CalculatorUnitTests/Test.resw
Original file line number Diff line number Diff line change
Expand Up @@ -324,6 +324,9 @@
<data name="Meters-Nanometers">
<value>0.000000001</value>
</data>
<data name="Meters-Angstroms">
<value>0.0000000001</value>
</data>
<data name="Meters-Centimeters">
<value>0.01</value>
</data>
Expand Down Expand Up @@ -588,8 +591,8 @@
<data name="Milliliters-Milliliters" xml:space="preserve">
<value>1</value>
</data>
<data name="Nanometers-Microns-3" xml:space="preserve">
<value>0.003</value>
<data name="Angstroms-Nanometers-3" xml:space="preserve">
<value>0.3</value>
</data>
<data name="Joules-Kilowatthour" xml:space="preserve">
<value>3600000</value>
Expand Down

0 comments on commit ff16a72

Please sign in to comment.