中级农民
- 积分
- 118
- 大米
- 颗
- 鳄梨
- 个
- 水井
- 尺
- 蓝莓
- 颗
- 萝卜
- 根
- 小米
- 粒
- 学分
- 个
- 注册时间
- 2013-8-29
- 最后登录
- 1970-1-1
|
asterid 发表于 2013-9-5 08:03 ![]()
可以把fail的那些测试信息贴出来。这个autograder的错误信息蛮详细的。
不好意思了,各位,13个测试里边只对了两个,测试信息有点长:
Tests 2 through 8 create a Percolation object using your code, then repeatedly
open sites using open(i, j). After each call to open, we check that isFull(),
isOpen(), and percolates() return the corrrect results.
Test 2: Open predetermined list of sites using files
* filename = input6.txt
isFull(2, 1) returns wrong value [after 12 total calls to open()]
- student = true
- reference = false
* filename = input8.txt
isFull(2, 1) returns wrong value [after 13 total calls to open()]
- student = true
- reference = false
* filename = input8-no.txt
* filename = input10-no.txt
* filename = greeting57.txt
* filename = heart25.txt
==> FAILED
Test 3: Open random sites until system percolates (then test is terminated)
* N = 3
isFull(2, 1) returns wrong value [after 3 total calls to open()]
- student = true
- reference = false
* N = 5
* N = 10
* N = 10
* N = 20
* N = 20
* N = 50
isFull(2, 1) returns wrong value [after 123 total calls to open()]
- student = true
- reference = false
* N = 50
==> FAILED
Test 4: Opens predetermined sites, but where N = 1 and N = 2 (corner case test)
* filename = input1.txt
percolates() returns wrong value [after 0 total calls to open()]
- student = true
- reference = false
* filename = input1-no.txt
percolates() returns wrong value [after 0 total calls to open()]
- student = true
- reference = false
* filename = input2.txt
* filename = input2-no.txt
==> FAILED
Test 5: Check for backwash with predetermined sites
* filename = input20.txt
* filename = input10.txt
* filename = input50.txt
isFull(2, 1) returns wrong value [after 172 total calls to open()]
- student = true
- reference = false
==> FAILED
Test 6: Check for backwash with predetermined sites that havemultiple percolating paths
* filename = input3.txt
isFull(2, 1) returns wrong value [after 5 total calls to open()]
- student = true
- reference = false
* filename = input4.txt
isFull(2, 1) returns wrong value [after 3 total calls to open()]
- student = true
- reference = false
* filename = input7.txt
==> FAILED
Test 7: Predetermined sites with very long percolating path
* filename = snake13.txt
isFull(2, 1) returns wrong value [after 60 total calls to open()]
- student = true
- reference = false
* filename = snake101.txt
isFull(2, 1) returns wrong value [after 4694 total calls to open()]
- student = true
- reference = false
==> FAILED
Test 8: Opens every site
* filename = input5.txt
==> passed
Test 9: Create multiple Percolation objects at the same time
(to make sure you didn't store data in static variables)
isFull(2, 1) returns wrong value [after 7 total calls to open()]
- student = true
- reference = false
==> FAILED
Test 10: Open predetermined list of sites using file
but change the order in which methods are called
* filename = input8.txt; order = isFull(), isOpen(), percolates()
isFull(2, 1) returns wrong value [after 13 total calls to open()]
- student = true
- reference = false
* filename = input8.txt; order = isFull(), percolates(), isOpen()
isFull(2, 1) returns wrong value [after 13 total calls to open()]
- student = true
- reference = false
* filename = input8.txt; order = isOpen(), isFull(), percolates()
isFull(2, 1) returns wrong value [after 13 total calls to open()]
- student = true
- reference = false
* filename = input8.txt; order = isOpen(), percolates(), isFull()
isFull(2, 1) returns wrong value [after 13 total calls to open()]
- student = true
- reference = false
* filename = input8.txt; order = percolates(), isOpen(), isFull()
isFull(2, 1) returns wrong value [after 13 total calls to open()]
- student = true
- reference = false
* filename = input8.txt; order = percolates(), isFull(), isOpen()
isFull(2, 1) returns wrong value [after 13 total calls to open()]
- student = true
- reference = false
==> FAILED
Test 11: Call all methods in random order until just before system percolates
* N = 3
isFull(2, 1) returns wrong value [after 3 total calls to open()]
- student = true
- reference = false
* N = 5
* N = 7
isFull(2, 1) returns wrong value [after 4 total calls to open()]
- student = true
- reference = false
* N = 10
* N = 20
isFull(2, 1) returns wrong value [after 63 total calls to open()]
- student = true
- reference = false
* N = 50
isFull(2, 1) returns wrong value [after 59 total calls to open()]
- student = true
- reference = false
==> FAILED
Test 12: Call all methods in random order with inputs not prone to backwash
* N = 3
* N = 5
isFull(2, 1) returns wrong value [after 13 total calls to open()]
- student = true
- reference = false
* N = 7
isFull(2, 1) returns wrong value [after 19 total calls to open()]
- student = true
- reference = false
* N = 10
* N = 20
* N = 50
==> FAILED
Test 13: Call all methods in random order until all sites are open
* N = 3
isFull(2, 1) returns wrong value [after 5 total calls to open()]
- student = true
- reference = false
* N = 5
* N = 7
* N = 10
isFull(2, 1) returns wrong value [after 44 total calls to open()]
- student = true
- reference = false
* N = 20
isFull(2, 1) returns wrong value [after 146 total calls to open()]
- student = true
- reference = false
* N = 50
isFull(2, 1) returns wrong value [after 423 total calls to open()]
- student = true
- reference = false
==> FAILED
Total: 2/13 tests passed!
===============================================================
不知道能不能贴code出来啊,不管了,希望有大牛帮我看看到底是啥问题,这两天搞的我茶饭不思的。万分感谢啊。
private boolean[][] site; // site status indexed
private int grid; // grid size: grid*grid
private WeightedQuickUnionUF quickunion1; //weighted quick union tree
private WeightedQuickUnionUF quickunion2; // mirror to quickunion1
public Percolation(int N) // create N-by-N grid, with all sites blocked
{
grid = N;
site = new boolean[N][N];
quickunion1 = new WeightedQuickUnionUF(N*N+2);
quickunion2 = new WeightedQuickUnionUF(N*N+1);
for (int i =0; i <N; i++)
{
for (int j =0; j<N; j++)
{
site[i][j] = false;
}
}
for (int i=1; i<=N; i++) quickunion1.union(0,i); // 0 is the virtual top site
for (int i=0; i<N; i++) quickunion1.union(N*N+1,N*N-i); // N*N+1 is the virtual top site
for (int i=1; i<=N; i++) quickunion2.union(0,i); //connect mirror to virtual top site
}
public void open(int i, int j) // open site (row i, column j) if it is not already
{
if (i < 1 || i > grid || j < 1 || j > grid)
{
throw new IndexOutOfBoundsException();
}
site[i-1][j-1] = true;
if(i>1 && isOpen(i-1,j))
{
quickunion1.union((grid*(i-1)+(j-1)),(grid*(i-2)+(j-1)));
quickunion2.union((grid*(i-1)+(j-1)),(grid*(i-2)+(j-1)));
}
if(i<grid && isOpen(i+1,j))
{
quickunion1.union((grid*(i-1)+(j-1)),(grid*i+(j-1)));
quickunion2.union((grid*(i-1)+(j-1)),(grid*i+(j-1)));
}
if(j>1 && isOpen(i,j-1))
{
quickunion1.union((grid*(i-1)+(j-1)),(grid*(i-1)+(j-2)));
quickunion2.union((grid*(i-1)+(j-1)),(grid*(i-1)+(j-2)));
}
if(j<grid && isOpen(i,j+1))
{
quickunion1.union((grid*(i-1)+(j-1)),(grid*(i-1)+j));
quickunion2.union((grid*(i-1)+(j-1)),(grid*(i-1)+j));
}
}
public boolean isOpen(int i, int j) // is site (row i, column j) open?
{
if (i < 1 || i> grid || j < 1 || j > grid)
{
throw new IndexOutOfBoundsException();
}
return site[i-1][j-1] == true;
}
public boolean isFull(int i, int j) // is site (row i, column j) full?
{
if (i < 1 || i> grid || j < 1 || j > grid)
{
throw new IndexOutOfBoundsException();
}
return (site[i-1][j-1]== true) && (quickunion2.connected(0,(i-1)*grid+j-1));
}
public boolean percolates() // does the system percolate?
{
return quickunion1.connected(0,grid*grid+1);
}
|
|