Created
October 14, 2016 01:49
-
-
Save tandat2209/0ab913ec06e68fe2a953c04411c50efe to your computer and use it in GitHub Desktop.
Count angle made of hour hand and minute hand
This file contains hidden or 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
package com.company; | |
/** | |
* Created by tandat on 10/14/16. | |
*/ | |
public class ClockAngle { | |
public static void main(String[] args) { | |
System.out.println("Angle = " + countAngle(12, 15)); | |
} | |
public static double countAngle(int h, int m){ | |
// 1 phut = kim phut di duoc 6 do// one minute make | |
// = kim gio di duoc 0.5 do// one minute make | |
// 1 gio = kim gio di duoc 30 do | |
double mAngle = m * 6; | |
double hAngle = h * 30 + m * 0.5; | |
double angle = Math.abs(hAngle - mAngle); | |
angle = angle > 180 ? 360 - angle: angle; | |
return angle; | |
} | |
} |
This file contains hidden or 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
package com.company | |
import org.junit.Test | |
import org.junit.runner.JUnitCore | |
import org.junit.runner.Result | |
import org.junit.runner.notification.Failure | |
/** | |
* Created by tandat on 10/14/16. | |
*/ | |
class ClockAngleTest extends GroovyTestCase { | |
@Test | |
public static void testCountAngle(){ | |
double angle = ClockAngle.countAngle(0, 0); | |
println angle; | |
assertEquals(angle, 0.0); | |
angle = ClockAngle.countAngle(4, 10); | |
println angle; | |
assertEquals(angle, 65.0); | |
angle = ClockAngle.countAngle(8, 30); | |
println angle; | |
assertEquals(angle, 75.0); | |
} | |
public static void main(String[] args) { | |
Result result = JUnitCore.runClasses(ClockAngleTest.class); | |
for (Failure failure : result.getFailures()) { | |
System.out.println(failure.toString()); | |
} | |
System.out.println(result.wasSuccessful()); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment