Skip to content

Instantly share code, notes, and snippets.

@tandat2209
Created October 14, 2016 01:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tandat2209/0ab913ec06e68fe2a953c04411c50efe to your computer and use it in GitHub Desktop.
Save tandat2209/0ab913ec06e68fe2a953c04411c50efe to your computer and use it in GitHub Desktop.
Count angle made of hour hand and minute hand
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;
}
}
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