Update InputValidator and its test for API
This commit is contained in:
@@ -9,30 +9,122 @@ import java.util.Objects;
|
||||
public class InputValidator {
|
||||
|
||||
private static final List<InputItem> inputItems = Arrays.asList(
|
||||
new InputItem("input_size", false, "1"),
|
||||
new InputItem("input_income", false, "40000"),
|
||||
new InputItem("transportation_num_vehicles", false, "1"),
|
||||
new InputItem("transportation_miles1", false, "16100", false),
|
||||
new InputItem("transportation_fuels1", false, "2", false),
|
||||
new InputItem("transportation_mpg1", false, null, false),
|
||||
new InputItem("transportation_miles2", false, "13200", false),
|
||||
new InputItem("transportation_fuels2", false, "0", false),
|
||||
new InputItem("transportation_mpg2", false, "22", false),
|
||||
new InputItem("transportation_publicTrans", false, "436"),
|
||||
new InputItem("transportation_air", false, "3900"),
|
||||
new InputItem("housing_electricity_kwh_year", false, "12632"),
|
||||
new InputItem("housing_cleanPercent", false, "0"),
|
||||
new InputItem("housing_naturalGas_therms_year", false, "472"),
|
||||
new InputItem("housing_heatingOil_gallons_year", false, "73"),
|
||||
new InputItem("housing_square_feet", false, "1850"),
|
||||
new InputItem("housing_water_sewage", false, "100"),
|
||||
new InputItem("food_meat_fish_eggs", true, "2.4"),
|
||||
new InputItem("food_grains", true, "4.1"),
|
||||
new InputItem("food_dairy", true, "2.2"),
|
||||
new InputItem("food_fruit_vegetables", true, "3.5"),
|
||||
new InputItem("food_snacks_drinks", true, "3.4"),
|
||||
new InputItem("shopping_goods", false, "1310"),
|
||||
new InputItem("shopping_services", false, "2413")
|
||||
new InputItem("input_location", false, "Chicago"),
|
||||
new InputItem("input_location_mode", false, "1"),
|
||||
new InputItem("input_size", false, "3"),
|
||||
new InputItem("input_income", false, "3000"),
|
||||
new InputItem("input_population", false, "1"),
|
||||
new InputItem("input_changed", false, "0"),
|
||||
new InputItem("input_footprint_household_adults", false, "0"),
|
||||
new InputItem("input_footprint_household_children", false, "0"),
|
||||
new InputItem("input_footprint_transportation_num_vehicles", false, "1"),
|
||||
new InputItem("input_footprint_transportation_miles1", false, "16100", false),
|
||||
new InputItem("input_footprint_transportation_mpg1", false, "22", false),
|
||||
new InputItem("input_footprint_transportation_fuel1", false, "0", false),
|
||||
new InputItem("input_footprint_transportation_miles2", false, "0", false),
|
||||
new InputItem("input_footprint_transportation_fuel2", false, "0", false),
|
||||
new InputItem("input_footprint_transportation_mpg2", false, "0", false),
|
||||
new InputItem("input_footprint_transportation_miles3", false, "0", false),
|
||||
new InputItem("input_footprint_transportation_fuel3", false, "0", false),
|
||||
new InputItem("input_footprint_transportation_mpg3", false, "0", false),
|
||||
new InputItem("input_footprint_transportation_miles4", false, "0", false),
|
||||
new InputItem("input_footprint_transportation_fuel4", false, "0", false),
|
||||
new InputItem("input_footprint_transportation_mpg4", false, "0", false),
|
||||
new InputItem("input_footprint_transportation_miles5", false, "0", false),
|
||||
new InputItem("input_footprint_transportation_fuel5", false, "0", false),
|
||||
new InputItem("input_footprint_transportation_mpg5", false, "0", false),
|
||||
new InputItem("input_footprint_transportation_miles6", false, "0", false),
|
||||
new InputItem("input_footprint_transportation_fuel6", false, "0", false),
|
||||
new InputItem("input_footprint_transportation_mpg6", false, "0", false),
|
||||
new InputItem("input_footprint_transportation_miles7", false, "0", false),
|
||||
new InputItem("input_footprint_transportation_fuel7", false, "0", false),
|
||||
new InputItem("input_footprint_transportation_mpg7", false, "0", false),
|
||||
new InputItem("input_footprint_transportation_miles8", false, "0", false),
|
||||
new InputItem("input_footprint_transportation_fuel8", false, "0", false),
|
||||
new InputItem("input_footprint_transportation_mpg8", false, "0", false),
|
||||
new InputItem("input_footprint_transportation_miles9", false, "0", false),
|
||||
new InputItem("input_footprint_transportation_fuel9", false, "0", false),
|
||||
new InputItem("input_footprint_transportation_mpg9", false, "0", false),
|
||||
new InputItem("input_footprint_transportation_miles10", false, "0", false),
|
||||
new InputItem("input_footprint_transportation_fuel10", false, "0", false),
|
||||
new InputItem("input_footprint_transportation_mpg10", false, "0", false),
|
||||
new InputItem("input_footprint_transportation_groundtype", false, "0"),
|
||||
new InputItem("input_footprint_transportation_publictrans", false, "436"),
|
||||
new InputItem("input_footprint_transportation_bus", false, "174"),
|
||||
new InputItem("input_footprint_transportation_transit", false, "131"),
|
||||
new InputItem("input_footprint_transportation_commuter", false, "87"),
|
||||
new InputItem("input_footprint_transportation_intercity", false, "44"),
|
||||
new InputItem("input_footprint_transportation_airtype", false, "0"),
|
||||
new InputItem("input_footprint_transportation_airtotal", false, "6"),
|
||||
new InputItem("input_footprint_transportation_airshort", false, "3"),
|
||||
new InputItem("input_footprint_transportation_airmedium", false, "3"),
|
||||
new InputItem("input_footprint_transportation_airlong", false, "0"),
|
||||
new InputItem("input_footprint_transportation_airextended", false, "0"),
|
||||
new InputItem("input_footprint_housing_cdd", false, "40000"),
|
||||
new InputItem("input_footprint_housing_hdd", false, "40000"),
|
||||
new InputItem("input_footprint_housing_electricity_type", false, "0"),
|
||||
new InputItem("input_footprint_housing_electricity_dollars", false, "1200"),
|
||||
new InputItem("input_footprint_housing_electricity_kwh", false, "12632"),
|
||||
new InputItem("input_footprint_housing_cleanpercent", false, "0"),
|
||||
new InputItem("input_footprint_housing_naturalgas_type", false, "0"),
|
||||
new InputItem("input_footprint_housing_naturalgas_dollars", false, "600"),
|
||||
new InputItem("input_footprint_housing_naturalgas_therms", false, "472"),
|
||||
new InputItem("input_footprint_housing_naturalgas_cuft", false, "472444"),
|
||||
new InputItem("input_footprint_housing_heatingoil_type", false, "0"),
|
||||
new InputItem("input_footprint_housing_heatingoil_dollars", false, "220"),
|
||||
new InputItem("input_footprint_housing_heatingoil_gallons", false, "73"),
|
||||
new InputItem("input_footprint_housing_heatingoil_dollars_per_gallon", false, "40000"),
|
||||
new InputItem("input_footprint_housing_squarefeet", false, "1850"),
|
||||
new InputItem("input_footprint_housing_watersewage", false, "100"),
|
||||
new InputItem("input_footprint_housing_gco2_per_kwh", false, "0"),
|
||||
new InputItem("input_footprint_shopping_food_meatfisheggs_default", true, "2.4"),
|
||||
new InputItem("input_footprint_shopping_food_meat_beefpork_default", true, "1.1"),
|
||||
new InputItem("input_footprint_shopping_food_meat_poultry_default", true, "0.7"),
|
||||
new InputItem("input_footprint_shopping_food_meat_fish_default", true, "0.3"),
|
||||
new InputItem("input_footprint_shopping_food_meat_other_default", true, "0.3"),
|
||||
new InputItem("input_footprint_shopping_food_fruitvegetables_default", true, "3.5"),
|
||||
new InputItem("input_footprint_shopping_food_dairy_default", true, "2.2"),
|
||||
new InputItem("input_footprint_shopping_food_cereals_default", true, "4.1"),
|
||||
new InputItem("input_footprint_shopping_food_otherfood_default", true, "3.4"),
|
||||
new InputItem("input_footprint_shopping_food_meattype", true, "0"),
|
||||
new InputItem("input_footprint_shopping_food_meatfisheggs", true, "2.4"),
|
||||
new InputItem("input_footprint_shopping_food_meat_beefpork", true, "2.4"),
|
||||
new InputItem("input_footprint_shopping_food_meat_poultry", true, "2.4"),
|
||||
new InputItem("input_footprint_shopping_food_meat_fish", true, "2.4"),
|
||||
new InputItem("input_footprint_shopping_food_meat_other", true, "2.4"),
|
||||
new InputItem("input_footprint_shopping_food_cereals", true, "4.1"),
|
||||
new InputItem("input_footprint_shopping_food_dairy", true, "2.2"),
|
||||
new InputItem("input_footprint_shopping_food_fruitvegetables", true, "3.5"),
|
||||
new InputItem("input_footprint_shopping_food_otherfood", true, "3.4"),
|
||||
new InputItem("input_footprint_shopping_goods_default_furnitureappliances", false, "1310"),
|
||||
new InputItem("input_footprint_shopping_goods_default_clothing", false, "1310"),
|
||||
new InputItem("input_footprint_shopping_goods_default_other_entertainment", false, "1310"),
|
||||
new InputItem("input_footprint_shopping_goods_default_other_office", false, "1310"),
|
||||
new InputItem("input_footprint_shopping_goods_default_other_personalcare", false, "1310"),
|
||||
new InputItem("input_footprint_shopping_goods_default_other_autoparts", false, "1310"),
|
||||
new InputItem("input_footprint_shopping_goods_default_other_medical", false, "1310"),
|
||||
new InputItem("input_footprint_shopping_goods_type", false, "1310"),
|
||||
new InputItem("input_footprint_shopping_goods_total", false, "1310"),
|
||||
new InputItem("input_footprint_shopping_goods_furnitureappliances", false, "362"),
|
||||
new InputItem("input_footprint_shopping_goods_clothing", false, "391"),
|
||||
new InputItem("input_footprint_shopping_goods_other_type", false, "0"),
|
||||
new InputItem("input_footprint_shopping_goods_other_total", false, "1311"),
|
||||
new InputItem("input_footprint_shopping_goods_other_entertainment", false, "200"),
|
||||
new InputItem("input_footprint_shopping_goods_other_office", false, "38"),
|
||||
new InputItem("input_footprint_shopping_goods_other_personalcare", false, "103"),
|
||||
new InputItem("input_footprint_shopping_goods_other_autoparts", false, "45"),
|
||||
new InputItem("input_footprint_shopping_goods_other_medical", false, "172"),
|
||||
new InputItem("input_footprint_shopping_services_type", false, "0"),
|
||||
new InputItem("input_footprint_shopping_services_total", false, "2413"),
|
||||
new InputItem("input_footprint_shopping_services_healthcare", false, "841"),
|
||||
new InputItem("input_footprint_shopping_services_education", false, "122"),
|
||||
new InputItem("input_footprint_shopping_services_communications", false, "163"),
|
||||
new InputItem("input_footprint_shopping_services_vehicleservices", false, "180"),
|
||||
new InputItem("input_footprint_shopping_services_finance", false, "566"),
|
||||
new InputItem("input_footprint_shopping_services_household", false, "28"),
|
||||
new InputItem("input_footprint_shopping_services_charity", false, "146"),
|
||||
new InputItem("input_footprint_shopping_services_miscservices", false, "114"),
|
||||
new InputItem("internal_state_abbreviation", false, "US")
|
||||
);
|
||||
|
||||
/**
|
||||
|
||||
@@ -13,50 +13,146 @@ public class InputValidatorTest {
|
||||
@Test
|
||||
public void validItemIdTest() {
|
||||
new InputValidator();
|
||||
assertEquals(InputValidator.isValidItem("transportation_num_vehicles"), true);
|
||||
assertEquals(InputValidator.isValidItem(
|
||||
"input_footprint_shopping_food_dairy_default"), true);
|
||||
assertEquals(InputValidator.isValidItem("test"), false);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void validItemValueTest() {
|
||||
assertTrue(InputValidator
|
||||
.isValidItemValue("transportation_num_vehicles", "4"));
|
||||
.isValidItemValue("input_footprint_transportation_num_vehicles", "4"));
|
||||
assertFalse(InputValidator
|
||||
.isValidItemValue("transportation_num_vehicles", "3.5"));
|
||||
assertFalse(InputValidator.isValidItemValue("food_grains", "hello"));
|
||||
assertTrue(InputValidator.isValidItemValue("food_grains", "5"));
|
||||
assertTrue(InputValidator.isValidItemValue("food_grains", "3.5"));
|
||||
.isValidItemValue("input_footprint_transportation_num_vehicles", "3.5"));
|
||||
assertFalse(InputValidator.isValidItemValue(
|
||||
"input_footprint_shopping_food_dairy_default", "hello"));
|
||||
assertTrue(InputValidator.isValidItemValue(
|
||||
"input_footprint_shopping_food_dairy_default", "5"));
|
||||
assertTrue(InputValidator.isValidItemValue(
|
||||
"input_footprint_shopping_food_dairy_default", "3.5"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getDefaultValuesTest() {
|
||||
Map<String, String> map = new HashMap<String, String>() {{
|
||||
put("input_size", "1");
|
||||
put("input_income", "40000");
|
||||
put("transportation_num_vehicles", "1");
|
||||
put("transportation_miles1", "16100");
|
||||
put("transportation_fuels1", "2");
|
||||
put("transportation_mpg1", null);
|
||||
put("transportation_miles2", "13200");
|
||||
put("transportation_fuels2", "0");
|
||||
put("transportation_mpg2", "22");
|
||||
put("transportation_publicTrans", "436");
|
||||
put("transportation_air", "3900");
|
||||
put("housing_electricity_kwh_year", "12632");
|
||||
put("housing_cleanPercent", "0");
|
||||
put("housing_naturalGas_therms_year", "472");
|
||||
put("housing_heatingOil_gallons_year", "73");
|
||||
put("housing_square_feet", "1850");
|
||||
put("housing_water_sewage", "100");
|
||||
put("food_meat_fish_eggs", "2.4");
|
||||
put("food_grains", "4.1");
|
||||
put("food_dairy", "2.2");
|
||||
put("food_fruit_vegetables", "3.5");
|
||||
put("food_snacks_drinks", "3.4");
|
||||
put("shopping_goods", "1310");
|
||||
put("shopping_services", "2413");
|
||||
put("input_location", "Chicago");
|
||||
put("input_location_mode", "1");
|
||||
put("input_size", "3");
|
||||
put("input_income", "3000");
|
||||
put("input_population", "1");
|
||||
put("input_changed", "0");
|
||||
put("input_footprint_household_adults", "0");
|
||||
put("input_footprint_household_children", "0");
|
||||
put("input_footprint_transportation_num_vehicles", "1");
|
||||
put("input_footprint_transportation_miles1", "16100");
|
||||
put("input_footprint_transportation_mpg1", "22");
|
||||
put("input_footprint_transportation_fuel1", "0");
|
||||
put("input_footprint_transportation_miles2", "0");
|
||||
put("input_footprint_transportation_fuel2", "0");
|
||||
put("input_footprint_transportation_mpg2", "0");
|
||||
put("input_footprint_transportation_miles3", "0");
|
||||
put("input_footprint_transportation_fuel3", "0");
|
||||
put("input_footprint_transportation_mpg3", "0");
|
||||
put("input_footprint_transportation_miles4", "0");
|
||||
put("input_footprint_transportation_fuel4", "0");
|
||||
put("input_footprint_transportation_mpg4", "0");
|
||||
put("input_footprint_transportation_miles5", "0");
|
||||
put("input_footprint_transportation_fuel5", "0");
|
||||
put("input_footprint_transportation_mpg5", "0");
|
||||
put("input_footprint_transportation_miles6", "0");
|
||||
put("input_footprint_transportation_fuel6", "0");
|
||||
put("input_footprint_transportation_mpg6", "0");
|
||||
put("input_footprint_transportation_miles7", "0");
|
||||
put("input_footprint_transportation_fuel7", "0");
|
||||
put("input_footprint_transportation_mpg7", "0");
|
||||
put("input_footprint_transportation_miles8", "0");
|
||||
put("input_footprint_transportation_fuel8", "0");
|
||||
put("input_footprint_transportation_mpg8", "0");
|
||||
put("input_footprint_transportation_miles9", "0");
|
||||
put("input_footprint_transportation_fuel9", "0");
|
||||
put("input_footprint_transportation_mpg9", "0");
|
||||
put("input_footprint_transportation_miles10", "0");
|
||||
put("input_footprint_transportation_fuel10", "0");
|
||||
put("input_footprint_transportation_mpg10", "0");
|
||||
put("input_footprint_transportation_groundtype", "0");
|
||||
put("input_footprint_transportation_publictrans", "436");
|
||||
put("input_footprint_transportation_bus", "174");
|
||||
put("input_footprint_transportation_transit", "131");
|
||||
put("input_footprint_transportation_commuter", "87");
|
||||
put("input_footprint_transportation_intercity", "44");
|
||||
put("input_footprint_transportation_airtype", "0");
|
||||
put("input_footprint_transportation_airtotal", "6");
|
||||
put("input_footprint_transportation_airshort", "3");
|
||||
put("input_footprint_transportation_airmedium", "3");
|
||||
put("input_footprint_transportation_airlong", "0");
|
||||
put("input_footprint_transportation_airextended", "0");
|
||||
put("input_footprint_housing_cdd", "40000");
|
||||
put("input_footprint_housing_hdd", "40000");
|
||||
put("input_footprint_housing_electricity_type", "0");
|
||||
put("input_footprint_housing_electrivity_dollars", "1200");
|
||||
put("input_footprint_housing_electricity_kwh", "12632");
|
||||
put("input_footprint_housing_cleanpercent", "0");
|
||||
put("input_footprint_housing_naturalgas_type", "0");
|
||||
put("input_footprint_housing_naturalgas_dollars", "600");
|
||||
put("input_footprint_housing_naturalgas_therms", "472");
|
||||
put("input_footprint_housing_naturalgas_cuft", "472444");
|
||||
put("input_footprint_housing_heatingoil_type", "0");
|
||||
put("input_footprint_housing_heatingoil_dollars", "220");
|
||||
put("input_footprint_housing_heatingoil_gallons", "73");
|
||||
put("input_footprint_housing_heatingoil_dollars_per_gallon", "40000");
|
||||
put("input_footprint_housing_squarefeet", "1850");
|
||||
put("input_footprint_housing_watersewage", "100");
|
||||
put("input_footprint_housing_gco2_per_kwh", "0");
|
||||
put("input_footprint_shopping_food_meatfisheggs_default", "2.4");
|
||||
put("input_footprint_shopping_food_meat_beefpork_default", "1.1");
|
||||
put("input_footprint_shopping_food_meat_poultry_default", "0.7");
|
||||
put("input_footprint_shopping_food_meat_fish_default", "0.3");
|
||||
put("input_footprint_shopping_food_meat_other_default", "0.3");
|
||||
put("input_footprint_shopping_food_fruitvegetables_default", "3.5");
|
||||
put("input_footprint_shopping_food_dairy_default", "2.2");
|
||||
put("input_footprint_shopping_food_cereals_default", "4.1");
|
||||
put("input_footprint_shopping_food_otherfood_default", "3.4");
|
||||
put("input_footprint_shopping_food_meattype", "0");
|
||||
put("input_footprint_shopping_food_meatfisheggs", "2.4");
|
||||
put("input_footprint_shopping_food_meat_beefpork", "2.4");
|
||||
put("input_footprint_shopping_food_meat_poultry", "2.4");
|
||||
put("input_footprint_shopping_food_meat_fish", "2.4");
|
||||
put("input_footprint_shopping_food_meat_other", "2.4");
|
||||
put("input_footprint_shopping_food_cereals", "4.1");
|
||||
put("input_footprint_shopping_food_dairy", "2.2");
|
||||
put("input_footprint_shopping_food_fruitvegetables", "3.5");
|
||||
put("input_footprint_shopping_food_otherfood", "3.4");
|
||||
put("input_footprint_shopping_goods_default_furnitureappliances", "1310");
|
||||
put("input_footprint_shopping_goods_default_clothing", "1310");
|
||||
put("input_footprint_shopping_goods_default_other_entertainment", "1310");
|
||||
put("input_footprint_shopping_goods_default_other_office", "1310");
|
||||
put("input_footprint_shopping_goods_default_other_personalcare", "1310");
|
||||
put("input_footprint_shopping_goods_default_other_autoparts", "1310");
|
||||
put("input_footprint_shopping_goods_default_other_medical", "1310");
|
||||
put("input_footprint_shopping_goods_type", "1310");
|
||||
put("input_footprint_shopping_goods_total", "1310");
|
||||
put("input_footprint_shopping_goods_furnitureappliances", "362");
|
||||
put("input_footprint_shopping_goods_clothing", "391");
|
||||
put("input_footprint_shopping_goods_other_type", "0");
|
||||
put("input_footprint_shopping_goods_other_total", "1311");
|
||||
put("input_footprint_shopping_goods_other_entertainment", "200");
|
||||
put("input_footprint_shopping_goods_other_office", "38");
|
||||
put("input_footprint_shopping_goods_other_personalcare", "103");
|
||||
put("input_footprint_shopping_goods_other_autoparts", "45");
|
||||
put("input_footprint_shopping_goods_other_medical", "172");
|
||||
put("input_footprint_shopping_services_type", "0");
|
||||
put("input_footprint_shopping_services_total", "2413");
|
||||
put("input_footprint_shopping_services_healthcare", "841");
|
||||
put("input_footprint_shopping_services_education", "122");
|
||||
put("input_footprint_shopping_services_communications", "163");
|
||||
put("input_footprint_shopping_services_vehicleservices", "180");
|
||||
put("input_footprint_shopping_services_finance", "566");
|
||||
put("input_footprint_shopping_services_household", "28");
|
||||
put("input_footprint_shopping_services_charity", "146");
|
||||
put("input_footprint_shopping_services_miscservices", "114");
|
||||
put("internal_state_abbreviation", "US");
|
||||
}
|
||||
};
|
||||
assertEquals(InputValidator.getDefaultValues(), map);
|
||||
assertTrue(map.size() == InputValidator.getDefaultValues().size());
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user