首页 / JAVA / java – 在测试中获取重复数据
java – 在测试中获取重复数据
内容导读
互联网集市收集整理的这篇技术教程文章主要介绍了java – 在测试中获取重复数据,小编现在分享给大家,供广大互联网技能从业者学习和参考。文章包含3456字,纯文字阅读大概需要5分钟。
内容图文
![java – 在测试中获取重复数据](/upload/InfoBanner/zyjiaocheng/818/41d97dc8ae7e41c6a751a8ce040a03b7.jpg)
当我运行以下测试用例时:
@Test(timeout=1000) public void shape_displayChar2_rot(){
String layout =
"b....\n"+
".....\n"+
"....b\n"+
"";
String expect =
"SHAPE z\n"+
"height: 5; width: 3; rotation: CW90\n"+
"..z\n"+
"...\n"+
"...\n"+
"...\n"+
"z..\n"+
"";
char newDC = 'z';
char dc = getDisplayChar(layout);
Shape shape = FitIt.makeShape(layout,dc);
shape.setDisplayChar(newDC);
shape.rotateCW();
assertEquals(newDC, shape.getDisplayChar());
String actual = shape.toString();
assertEquals(expect,actual);
}
我得到以下失败:
Expected:
SHAPE z
height: 5; width: 3; rotation: CW90
..z
...
...
...
z..
我的实际代码结果如下:
Actual:
SHAPE z
height: 5; width: 3; rotation: CW90
b....
.....
....b
..z
...
...
...
z..
上面测试用例的String布局通过rotateCW()旋转90度ClockWise并且还改变其角色.我的问题是为什么我得到:
b.... <<<<----- WHY AM I GETTING THIS ?
..... <<<<----- WHY AM I GETTING THIS ?
....b <<<<----- WHY AM I GETTING THIS ?
..z
...
...
...
z..
而不只是:
..z
...
...
...
z..
码:
import java.util.*;
public class CreateShape implements Shape {
private String layout;
private int height;
private int width;
private char dc;
private Rotation initialPos;
private char[][] shape;
//private char[][] rotatedShape = new char[height][width];// = new char[shape.length][shape[0].length];
public CreateShape(int height, int width, char dc, char[][] charLayout, String layout) {
this.height = height;
this.width = width;
this.dc = dc;
this.shape = charLayout;
this.layout = layout;
initialPos = Rotation.CW0;
//nextPos = Rotation.CW0;
}
public Rotation getRotation() {
return initialPos;
}
public int getHeight() {
return this.height;
}
public int getWidth() {
return this.width;
}
public char getDisplayChar() {
return dc;
}
public void setDisplayChar(char c) {
this.dc = c;
for (int i = 0; i < shape.length; i++) {
for (int j = 0; j < shape[0].length; j++) {
//if(shape[i][j] == '.')
//this.newLayout += shape[i][j];
if (shape[i][j] != '.') {
shape[i][j] = c;
}
}
//this.newLayout+="\n";
}
}
public void rotateCW() {
initialPos = initialPos.next();
int w = shape.length;
int h = shape[0].length;
char[][] swapped = new char[h][w];
for (int i = 0; i < h; i++) {
for (int j = 0; j < w; j++) {
swapped[i][j] = shape[w - j - 1][i];
layout += swapped[i][j];
}
layout += "\n";
}
height = swapped.length;
width = swapped[0].length;
}
public boolean isFilledAt(int row, int col) {
if (row < 0 || row >= height || col < 0 || col >= width) {
throw new FitItException("Oops! Out of bounds!");
} else {
for (int r = 0; r <= height; r++) {
for (int c = 0; c <= width; c++) {
if (shape[row][col] == dc) {
return true;
}
}
}
}
return false;
}
public String toString() {
return "SHAPE " + this.dc + "\n" +
"height: " + this.height + ";" + " width: " + this.width + "; " + getRotation().toString() + "\n" +
this.layout;
}
}
class FitIt
public class FitIt {
public static Shape makeShape(String layout, char displayChar) {
Shape result;
int height = 0;
int width = 0;
Scanner data = new Scanner(layout);
while (data.hasNextLine()) {
String line = data.nextLine();
width = line.length();
height++;
}
char[][] charLayout = new char[height][width];
Scanner data2 = new Scanner(layout);
for (int i = 0; i < height; i++) {
String line = data2.nextLine();
for (int j = 0; j < width; j++) {
if (line.charAt(j) != '.') {
charLayout[i][j] = displayChar;
}
if (line.charAt(j) == '.') {
charLayout[i][j] = line.charAt(j);
}
}
}
data2.close();
result = new CreateShape(height, width, displayChar, charLayout, layout);
return result;
}
解决方法:
在rotateCW()方法中,您忘记清除布局.您可以在for循环之前添加layout =“”并尝试一下.
内容总结
以上是互联网集市为您收集整理的java – 在测试中获取重复数据全部内容,希望文章能够帮你解决java – 在测试中获取重复数据所遇到的程序开发问题。 如果觉得互联网集市技术教程内容还不错,欢迎将互联网集市网站推荐给程序员好友。
内容备注
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 gblab@vip.qq.com 举报,一经查实,本站将立刻删除。
内容手机端
扫描二维码推送至手机访问。