Last active
January 10, 2017 21:14
-
-
Save jeremysimmons/26ade8d36e184f55cb17b3f922a5248d to your computer and use it in GitHub Desktop.
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
| void Main() | |
| { | |
| XunitRunner.Run(Assembly.GetExecutingAssembly()); | |
| } | |
| // Define other methods and classes here | |
| public class Class1 | |
| { | |
| [Theory] | |
| [MemberData("TestData", MemberType = typeof(Class1))] | |
| public void HourToAngleStrategy1(int hour, int expectedAngle) | |
| { | |
| Assert.Equal(HourToAngle(hour), expectedAngle); | |
| } | |
| [Theory] | |
| [MemberData("TestData", MemberType = typeof(Class1))] | |
| public void HourToAngleStrategy2(int hour, int expectedAngle) | |
| { | |
| Assert.Equal(HourToAngle2(hour), expectedAngle); | |
| } | |
| public static IEnumerable<object[]> TestData | |
| { | |
| get | |
| { | |
| yield return new object[] { 12, 90 }; | |
| yield return new object[] { 1, 60 }; | |
| yield return new object[] { 2, 30 }; | |
| yield return new object[] { 3, 0 }; | |
| yield return new object[] { 4, 330 }; | |
| yield return new object[] { 5, 300 }; | |
| yield return new object[] { 6, 270 }; | |
| yield return new object[] { 7, 240 }; | |
| yield return new object[] { 8, 210 }; | |
| yield return new object[] { 9, 180 }; | |
| yield return new object[] { 10, 150 }; | |
| yield return new object[] { 11, 120 }; | |
| } | |
| } | |
| int HourToAngle(int hour) | |
| { | |
| int angle = 0; | |
| if (hour <= 3) | |
| angle = ((3 - hour) * 30); | |
| else | |
| angle = ((12 - hour) * 30) + 90; | |
| return angle; | |
| } | |
| int HourToAngle2(int hour) | |
| { | |
| float angle = ((15 - hour) / 12f); | |
| float quotient = (int)angle; | |
| float minutes = angle - quotient; | |
| return (int)Math.Round(minutes * 360f, 0); | |
| } | |
| } | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment