【发布时间】:2014-09-24 21:35:33
【问题描述】:
我正在尝试使用 scalacheck 测试一个 java 类。 例如,我在 ...\src\main\java\
中有一个类 Queuepublic class Queue<Item> {
private Node first;
private Node last;
private int N;
private class Node {
Item item;
Node next;
}
public boolean isEmpty () { return first == null; }
public int size() { return N;}
public void enqueue(Item item) {
Node oldLast = last;
last = new Node();
last.item = item;
last.next = null;
if(isEmpty())
first = last;
else
oldLast = last;
N++;
}
public Item dequeue() {
Item item = first.item;
first = first.next;
if(isEmpty())
last = null;
N--;
return item;
}
}
然后我在 ...\src\test\scala\ 中有一个 Scala 测试类 QueueTest.scala\
import org.scalacheck.Gen.{choose, oneOf}
import org.scalacheck.Prop.forAll
import org.scalacheck.Gen.choose
import org.scalacheck._
import org.scalacheck.Prop._
class QueueTest extends Properties("Queue") {
Queue<Int> q;
property("enque") = Prop.forAll { (n: Int) =>
(q.enque(n) == n)
}
}
我只需要先了解如何扩展 Java 通用 Queue 类? 我要做的就是测试入队和出队方法。
我查看了 Rick Nillson 的 github 中的 StringUtils.scala 示例,但仍不清楚。
任何建议都将不胜感激
【问题讨论】:
-
这是我正在尝试测试的完整代码。 introcs.cs.princeton.edu/java/43stack/Queue.java.html
标签: scalacheck