-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathLesson3FrogJmp.cs
68 lines (58 loc) · 1.24 KB
/
Lesson3FrogJmp.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
/*
Lesson 3 Time Complexity: FrogJmp
Count minimal number of jumps from position X to Y
https://codility.com/programmers/task/frog_jmp/
*/
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System;
namespace CodilityLessonSolutions
{
[TestClass]
public class Lesson3FrogJmp
{
public int solution(int X, int Y, int D)
{
decimal d = ((decimal)Y - (decimal)X) / (decimal)D;
return (int)Math.Ceiling(d);
}
[TestMethod]
public void FrogJmpLargeInteger1()
{
int i = 1000000000;
Assert.AreEqual(0, solution(i, i, i));
}
[TestMethod]
public void FrogJmpLargeInteger2()
{
int i = 1000000000;
Assert.AreEqual(1, solution(i - 1, i, i));
}
[TestMethod]
public void FrogJmpLargeInteger3()
{
int i = 1000000000;
Assert.AreEqual(i - 1, solution(1, i, 1));
}
[TestMethod]
public void FrogJmpLargeInteger4()
{
int i = 1000000000;
Assert.AreEqual(499999998, solution(5, i, 2));
}
[TestMethod]
public void FrogJmpSmallInteger1()
{
Assert.AreEqual(1, solution(1, 2, 1));
}
[TestMethod]
public void FrogJmpSmallInteger2()
{
Assert.AreEqual(4, solution(1, 5, 1));
}
[TestMethod]
public void FrogJmpSmallInteger3()
{
Assert.AreEqual(3, solution(10, 85, 30));
}
}
}