ConversionToolSpec.java 3.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. import static org.junit.Assert.assertEquals;
  2. import org.junit.Test;
  3. public class ConversionToolSpec {
  4. @Test
  5. public void shouldConvertCentimetersToInches() {
  6. float inches = ConversionTool.CentimetersToInches(2f);
  7. assertEquals(0.7874f, inches, 0.001);
  8. }
  9. @Test
  10. public void shouldConvertZeroCentimetersToZeroInches() {
  11. float inches = ConversionTool.CentimetersToInches(0);
  12. assertEquals(0, inches, 0.0);
  13. }
  14. @Test
  15. public void shouldConvertNegativeCentimetersToZeroInches() {
  16. float inches = ConversionTool.CentimetersToInches(-5);
  17. assertEquals(0, inches, 0.0);
  18. }
  19. @Test
  20. public void shouldConvertInchesToCentimeters() {
  21. float centimeters = ConversionTool.InchesToCentimeters(4f);
  22. assertEquals(10.16f, centimeters, 0.001);
  23. }
  24. @Test
  25. public void shouldConvertZeroInchesToZeroCentimeters() {
  26. float centimeters = ConversionTool.InchesToCentimeters(0);
  27. assertEquals(0, centimeters, 0.0);
  28. }
  29. @Test
  30. public void shouldConvertNegativeInchesToZeroCentimeters() {
  31. float centimeters = ConversionTool.InchesToCentimeters(-5);
  32. assertEquals(0, centimeters, 0.0);
  33. }
  34. @Test
  35. public void shouldConvertFeetToMeters() {
  36. float meters = ConversionTool.FeetToMeters(5f);
  37. assertEquals(1.524f, meters, 0.001);
  38. }
  39. @Test
  40. public void shouldConvertZeroFeetToZeroMeters() {
  41. float meters = ConversionTool.FeetToMeters(0);
  42. assertEquals(0, meters, 0.0);
  43. }
  44. @Test
  45. public void shouldConvertNegativeFeetToZeroMeters() {
  46. float meters = ConversionTool.FeetToMeters(-10);
  47. assertEquals(0, meters, 0.0);
  48. }
  49. @Test
  50. public void shouldConvertMetersToFeet() {
  51. float feet = ConversionTool.MetersToFeet(9f);
  52. assertEquals(29.5276f, feet, 0.001);
  53. }
  54. @Test
  55. public void shouldConvertZeroMetersToZeroFeet() {
  56. float feet = ConversionTool.MetersToFeet(0);
  57. assertEquals(0, feet, 0.0);
  58. }
  59. @Test
  60. public void shouldConvertNegativeMetersToZeroFeet() {
  61. float feet = ConversionTool.MetersToFeet(-10);
  62. assertEquals(0, feet, 0.0);
  63. }
  64. @Test
  65. public void shouldConvertFahrenheitToCelsius() {
  66. float celsius = ConversionTool.FahrenheitToCelsius(80);
  67. assertEquals(26.67, celsius, 0.01);
  68. }
  69. @Test
  70. public void shouldConvertCelsiusToFahrenheit() {
  71. float fahrenheit = ConversionTool.CelsiusToFahrenheit(26.67f);
  72. assertEquals(80, fahrenheit, 0.01);
  73. }
  74. @Test
  75. public void shouldConvertMphToKph(){
  76. float kph = ConversionTool.MphToKph(24f);
  77. assertEquals(38.62, kph, 0.01);
  78. }
  79. @Test
  80. public void shouldConvertZeroMphToZeroKph(){
  81. float kph = ConversionTool.MphToKph(0f);
  82. assertEquals(0, kph, 0.0);
  83. }
  84. @Test
  85. public void shouldConvertNegativeMphToZeroKph(){
  86. float kph = ConversionTool.MphToKph(-50f);
  87. assertEquals(0, kph, 0.0);
  88. }
  89. @Test
  90. public void shouldConvertKphToMph(){
  91. float mph = ConversionTool.KphToMph(6.44f);
  92. assertEquals(4, mph, 0.01);
  93. }
  94. @Test
  95. public void shouldConvertZeroKphToZeroMph(){
  96. float mph = ConversionTool.KphToMph(0f);
  97. assertEquals(0, mph, 0.0);
  98. }
  99. @Test
  100. public void shouldConvertNegativeKphToZeroMph(){
  101. float mph = ConversionTool.KphToMph(-50f);
  102. assertEquals(0, mph, 0.0);
  103. }
  104. }