Skip to content

Commit ea27506

Browse files
committed
重置测试框架
1 parent c79b0c6 commit ea27506

File tree

7 files changed

+78
-29
lines changed

7 files changed

+78
-29
lines changed

src/ice1000/models/Area.kt

+11
Original file line numberDiff line numberDiff line change
@@ -33,4 +33,15 @@ abstract class Area(val origin: BufferedImage) {
3333
Line(this, point).set.forEach { p -> if (this@Area[p.x, p.y]) return false }
3434
return true
3535
}
36+
37+
private fun Point.legal() = x >= 0 && y >= 0 && x < origin.width && y < origin.height
38+
39+
// fun drawArea(point: Point): Set<Point> {
40+
// val queue = LinkedBlockingQueue<Point>()
41+
// val set = HashSet<Point>()
42+
// queue.put(point)
43+
// while (queue.isNotEmpty()) {
44+
// queue.peek()
45+
// }
46+
// }
3647
}

src/ice1000/models/Line.kt

+4-4
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,12 @@ open class Line(one: Point, two: Point) {
1616
val set = HashSet<Point>()
1717

1818
init {
19-
(Math.min(one.x, two.x)..Math.max(one.x, two.x)).forEach { x -> if (b != 0) set.add(Point(x, x2y(x))) }
20-
(Math.min(one.y, two.y)..Math.max(one.y, two.y)).forEach { y -> if (a != 0) set.add(Point(y2x(y), y)) }
19+
(Math.min(one.x, two.x)..Math.max(one.x, two.x)).forEach { x -> set.add(Point(x, x2y(x))) }
20+
(Math.min(one.y, two.y)..Math.max(one.y, two.y)).forEach { y -> set.add(Point(y2x(y), y)) }
2121
}
2222

23-
fun x2y(x: Int) = -(a * x + c) / b
24-
fun y2x(y: Int) = -(b * y + c) / a
23+
fun x2y(x: Int) = if (b == 0) c / a else -(a * x + c) / b
24+
fun y2x(y: Int) = if (a == 0) c / b else -(b * y + c) / a
2525

2626
override operator fun equals(other: Any?): Boolean {
2727
if (other == null || other !is Line) return false

src/ice1000/models/Point.kt

+1-11
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,7 @@ package ice1000.models
44
* @author ice1000
55
* Created by ice1000 on 2016/8/8.
66
*/
7-
data class Point(val x: Int, val y: Int) {
8-
9-
var quadrant = 0
10-
11-
/** 计算象限 */
12-
init {
13-
quadrant += if (x >= 0) 1 else 2
14-
quadrant += if (y >= 0) 0 else 3
15-
if (quadrant == 5) quadrant = 3
16-
}
7+
open class Point(val x: Int, val y: Int) {
178

189
/** 计算两点距离 */
1910
infix fun distance(p: Point) = Math.sqrt(((p.x - x) * (p.x - x) + (p.y - y) * (p.y - y)).toDouble()).toInt()
@@ -28,7 +19,6 @@ data class Point(val x: Int, val y: Int) {
2819
override fun hashCode(): Int {
2920
var result = x
3021
result = 31 * result + y
31-
result = 31 * result + quadrant
3222
return result
3323
}
3424
}

src/ice1000/models/Position.kt

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
package ice1000.models
2+
3+
/**
4+
* @author ice1000
5+
* Created by ice1000 on 2016/8/11.
6+
*/
7+
class Position(x: Int, y: Int): Point(x, y) {
8+
9+
var quadrant = 0
10+
11+
/** 计算象限 */
12+
init {
13+
quadrant += if (x >= 0) 1 else 2
14+
quadrant += if (y >= 0) 0 else 3
15+
if (quadrant == 5) quadrant = 3
16+
}
17+
18+
}

test/core/Test.java

+13-7
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
package core;
22

3-
import core.models.PointTest;
4-
53
/**
4+
* My own test framework.
5+
* Created by ice1000 on 2016/8/8.
6+
*
67
* @author ice1000
7-
* Created by ice1000 on 2016/8/8.
8+
* <p>
89
*/
910
public class Test {
1011

@@ -25,11 +26,16 @@ protected void assertEqual(Object x, Object y) {
2526
if (x != y && !x.equals(y)) throw new AssertionError();
2627
}
2728

28-
protected void run() {
29-
assertEqual(1 + 2, 3);
29+
/**
30+
* show an object on console (calling toString)
31+
*
32+
* @param any object to show
33+
*/
34+
protected void show(Object any) {
35+
System.out.println("[type: " + any.getClass().toString() + ", value: " + any.toString() + ']');
3036
}
3137

32-
public static void main(String[] args) {
33-
new PointTest();
38+
protected void run() {
39+
assertEqual(1 + 2, 3);
3440
}
3541
}

test/core/models/PointTest.java

+8-7
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,18 @@
44
import ice1000.models.Point;
55

66
/**
7+
* Created by ice1000 on 2016/8/11.
78
* @author ice1000
8-
* Created by ice1000 on 2016/8/8.
99
*/
10-
public class PointTest extends Test {
11-
10+
public class PointTest extends Test{
1211
@Override
1312
protected void run() {
14-
assertEqual(new Point(1, 1).getQuadrant(), 1);
15-
assertEqual(new Point(-1, 1).getQuadrant(), 2);
16-
assertEqual(new Point(-1, -1).getQuadrant(), 3);
17-
assertEqual(new Point(1, -1).getQuadrant(), 4);
1813
assertEqual(new Point(1, 2), new Point(1, 2));
14+
assertEqual(new Point(1, 1).distance(new Point(2, 1)), 1);
15+
show(new Point(0, 0).distance(new Point(1, 1)));
16+
}
17+
18+
public static void main(String[] args) {
19+
new PointTest();
1920
}
2021
}

test/core/models/PositionTest.java

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
package core.models;
2+
3+
import core.Test;
4+
import ice1000.models.Position;
5+
6+
/**
7+
* Created by ice1000 on 2016/8/8.
8+
* @author ice1000
9+
*/
10+
public class PositionTest extends Test {
11+
12+
@Override
13+
protected void run() {
14+
assertEqual(new Position(1, 1).getQuadrant(), 1);
15+
assertEqual(new Position(-1, 1).getQuadrant(), 2);
16+
assertEqual(new Position(-1, -1).getQuadrant(), 3);
17+
assertEqual(new Position(1, -1).getQuadrant(), 4);
18+
}
19+
20+
public static void main(String[] args) {
21+
new PositionTest();
22+
}
23+
}

0 commit comments

Comments
 (0)