public static void main(String[] args) { Temperature myTemp = new Temperature(32); System.out.println(myTemp.getFtemp()); System.out.println(myTemp.getCelsius()); System.out.println(myTemp.getKelvin()); }
private static OrderedMap<Long, Double[]> _MergeDataSets(boolean F, TemperatureSet TSList[]) { /* merge temperature data sets */ OrderedMap<Long, Double[]> rowMap = new OrderedMap<Long, Double[]>(); if (!ListTools.isEmpty(TSList)) { for (int d = 0; d < TSList.length; d++) { TemperatureSet TS = TSList[d]; if (TS != null) { Collection<Temperature> TList = TS.getTemperatures(); for (Temperature T : TList) { Long ts = new Long(T.getTimestamp()); Double tmp = new Double(T.getTemperature(F)); Double row[] = rowMap.get(ts); if (row == null) { row = new Double[TSList.length]; rowMap.put(ts, row); } row[d] = tmp; } } } } /* sort by timestamp */ rowMap.sortKeys(new ListTools.NumberComparator<Long>()); /* return */ return rowMap; }
/** Test of plus method, of class Temperature. */ @Test public void testPlus() { Temperature other = new Temperature(10); Temperature instance = new Temperature(10); Temperature expResult = new Temperature(20); Temperature result = instance.plus(other); assertEquals(expResult, result); }
public Hashtable<_CollectionFeature, Sample> read(Tuple tuple) { short[] data = ((Uint8Array) tuple.get(3).getValue()).serializeValue(); int target_gw = (data[2] << 8) + data[3]; int node_identifier = (data[4] << 8) + data[5]; int period = (data[6] << 8) + data[7]; int info_id = (data[8] << 8) + data[9]; int value = (data[10] << 8) + data[11]; if (log) { try { Timestamp ts = new Timestamp(new Date().getTime()); writer = new FileWriter(fileName, true); writer.write( "GW\t" + target_gw + "\tID\t" + node_identifier + "\tSEQ_NO\t" + period + "\tINFO_ID\t" + info_id + "\tVALUE\t" + value + "\t" + ts); writer.write("\n"); writer.flush(); writer.close(); } catch (IOException e) { e.printStackTrace(); } } Hashtable<_CollectionFeature, Sample> ret = new Hashtable<_CollectionFeature, Sample>(); Vector<Integer> v = new Vector<Integer>(); switch (info_id) { case Constants.ROUTING_PARENT: v.add(value); ret.put(Parent.getFeature(), new Sample(v, new Date(System.currentTimeMillis()))); break; case Constants.ROUTING_PARENT_LQI: v.add(value); ret.put(ParentQuality.getFeature(), new Sample(v, new Date(System.currentTimeMillis()))); break; case Constants.BATTERY: ret.put( Battery.getFeature(), new Sample(Battery.convert((int) value), new Date(System.currentTimeMillis()))); break; case Constants.TEMPERATURE: ret.put( Temperature.getFeature(), new Sample(Temperature.convert((int) value), new Date(System.currentTimeMillis()))); break; } return ret; }
@Test public void testRangeValidator() { deleteAndPopulateTable("temperatures"); Temperature t = new Temperature(); // specified value in range t.set("temp", 59); t.validate(); a(t.errors().size()).shouldBeEqual(0); // specified value out of range t.set("temp", 200); t.validate(); a(t.errors().size()).shouldBeEqual(1); a(t.errors().get("temp")).shouldBeEqual("temperature cannot be less than 0 or more than 100"); // pass double, which is a different type than range values specified in the model, exception is // thrown t.set("temp", 200.00); Exception ex = null; try { t.validate(); } catch (Exception e) { ex = e; } a(ex).shouldBeType(IllegalArgumentException.class); }
/** ** Update min/max temperatures */ private void _updateMinMaxTemperature() { this.minTempC = 9999.0; this.maxTempC = -9999.0; for (Temperature T : this.tempList) { double tempC = T.getTemperatureC(); // temperature guaranteed valid if (tempC < this.minTempC) { this.minTempC = tempC; } if (tempC > this.maxTempC) { this.maxTempC = tempC; } } }
/** ** Adds the specified temperature to this data set */ public boolean addTemperature(Temperature T) { if (Temperature.isValid(T)) { // valid timestamp and temperature this.tempList.add(T); double tempC = T.getTemperatureC(); if (tempC < this.minTempC) { this.minTempC = tempC; } if (tempC > this.maxTempC) { this.maxTempC = tempC; } return true; } else { return false; } }
@Test public void unitToStringTest_Fahrenheit() { Temperature fahrenheitTemperature = new Temperature(0, Temperature.Units.FAHRENHEIT); assertEquals("буF", fahrenheitTemperature.unitsToString()); }
// getValue() test for Kelvin @Test public void getValueTest_Kelvin() { Temperature kelvinTemperature = new Temperature(0, Temperature.Units.KELVIN); assertEquals(0, kelvinTemperature.getValue(), 0); }
@Test public void unitToStringTest_Kelvin() { Temperature kelvinTemperature = new Temperature(0, Temperature.Units.KELVIN); assertEquals("K", kelvinTemperature.unitsToString()); }
@Test public void unitToStringTest_Celsius() { Temperature celciusTemperature = new Temperature(0, Temperature.Units.CELSIUS); assertEquals("буC", celciusTemperature.unitsToString()); }
@Test public void hashCodeShouldBeEqualToDegreesKelvin() { assertEquals(786, temperature.hashCode()); }
@Test public void shouldNotBeEqualToNull() { assertFalse(temperature.equals(null)); }
@Test public void changeUnitsTestForFAHRENHEITToCELSIUS() { Temperature fahrenheitTemperature = new Temperature(0, Temperature.Units.FAHRENHEIT); fahrenheitTemperature.changeUnits(Temperature.Units.CELSIUS); assertEquals(Temperature.Units.CELSIUS, fahrenheitTemperature.getUnits()); }
// getValue() test for Fahrenheit @Test public void getValueTest_Fahrenheit() { Temperature fahrenheitTemperature = new Temperature(0, Temperature.Units.FAHRENHEIT); assertEquals(0, fahrenheitTemperature.getValue(), 0); }
@Test public void changeUnitsTestForCELSIUSToFAHRENHEIT() { Temperature celciusTemperature = new Temperature(0, Temperature.Units.CELSIUS); celciusTemperature.changeUnits(Temperature.Units.FAHRENHEIT); assertEquals(Temperature.Units.FAHRENHEIT, celciusTemperature.getUnits()); }
// changeUnits() test for Fahrenheit @Test public void changeUnitsTestForFAHRENHEITToKELVIN() { Temperature fahrenheitTemperature = new Temperature(0, Temperature.Units.FAHRENHEIT); fahrenheitTemperature.changeUnits(Temperature.Units.KELVIN); assertEquals(Temperature.Units.KELVIN, fahrenheitTemperature.getUnits()); }
// changeUnits() test for Celsius @Test public void changeUnitsTestForCELSIUSToKELVIN() { Temperature celciusTemperature = new Temperature(0, Temperature.Units.CELSIUS); celciusTemperature.changeUnits(Temperature.Units.KELVIN); assertEquals(Temperature.Units.KELVIN, celciusTemperature.getUnits()); }
@Test public void changeUnitsTestForKELVINToFAHRENHEIT() { Temperature kelvinTemperature = new Temperature(0, Temperature.Units.KELVIN); kelvinTemperature.changeUnits(Temperature.Units.FAHRENHEIT); assertEquals(Temperature.Units.FAHRENHEIT, kelvinTemperature.getUnits()); }
@Test public void shouldConvertToStringWithUnits() { assertEquals("512.85 degrees C", temperature.toString()); }
// getValue() test for Celsius @Test public void getValueTest_Celsius() { Temperature celciusTemperature = new Temperature(0, Temperature.Units.CELSIUS); assertEquals(0, celciusTemperature.getValue(), 0); }
// changeUnits() test for Kelvin @Test public void changeUnitsTestForKELVINToCELSIUS() { Temperature kelvinTemperature = new Temperature(0, Temperature.Units.KELVIN); kelvinTemperature.changeUnits(Temperature.Units.CELSIUS); assertEquals(Temperature.Units.CELSIUS, kelvinTemperature.getUnits()); }
@Test public void getValueTest_Celsius_KelvinEqualToZero() { Temperature celciusTemperature = new Temperature(-273.15, Temperature.Units.CELSIUS); assertEquals(-273.15, celciusTemperature.getValue(), 0); }
@Test public void shouldNotBeEqualToWeirdThing() { assertFalse(temperature.equals((Object) (new String("hello")))); }
@Test public void getValueTest_Fahrenheit_KelvinEqualToZero() { Temperature fahrenheitTemperature = new Temperature(-459.67, Temperature.Units.FAHRENHEIT); assertEquals(-459.67, fahrenheitTemperature.getValue(), 0); }
@Test public void shouldBeEqualToEqualTemperatureAsObject() { assertTrue(temperature.equals((Object) (new Temperature(786)))); }
@Test public void getUnitTest_Celsius() { Temperature celciusTemperature = new Temperature(0, Temperature.Units.CELSIUS); assertEquals(Temperature.Units.CELSIUS, celciusTemperature.getUnits()); }
public void getUnitTest_Fahrenheit() { Temperature fahrenheitTemperature = new Temperature(0, Temperature.Units.FAHRENHEIT); assertEquals(Temperature.Units.FAHRENHEIT, fahrenheitTemperature.getUnits()); }
@Test public void getUnitTest_Kelvin() { Temperature kelvinTemperature = new Temperature(0, Temperature.units.KELVIN); assertEquals(Temperature.Units.KELVIN, kelvinTemperature.getUnits()); }
@Test public void shouldNotBeEqualToUnEqualTemperature() { assertFalse(temperature.equals(new Temperature(785))); }