为什么我的代码未能通过以下测试?

时间:2019-09-16 16:32:19

标签: java

所以我的代码应该返回以下内容:

Hounsfield单位通过窗口映射到{@code 0}到{@code 1}范围内的实数。值小于lo的Hounsfield单位被映射到值{@code 0}。值大于hi的Hounsfield单位映射到值{@code 1}。值v在lo和hi之间的Hounsfield单位映射到值(v-lo)/ width。

我已经通过了之前的所有JUnit测试,并假定我的公共双图(Hounsfield f)是问题吗?

我完成了另一个名为Hounsfield的课程,它输出他们要的值v。

{
  created_on: '2019-09-16T16:26:49.885Z',
  name: 'UPDATED CREATE BOARD TEST',
  threads: [],
  updated_on: '2019-09-16T16:26:49.885Z',
  _id: 'c8ebf4d0-d89e-11e9-81ae-1dc34f066a52',
  delete_password: 'abcd123',
  loading: [Object],
  error: [Object],
  genUuidV1: [Function],
  now: [Function]
}

我认为assertEquals的失败意味着我的返回结果是错误的吗?

实际测试如下:

public class HounsfieldWindow {
private int level, width;

public HounsfieldWindow(int level, int width) {
    setLevel(level);
    setWidth(width);
}

public HounsfieldWindow() {
    this(0, 400); 
}

public int getLevel() {
    return level;
}

public int setLevel(int level) {
    if (level < Hounsfield.MIN_VALUE || level > Hounsfield.MAX_VALUE) {
        throw new IllegalArgumentException();
    }
    int data = this.level;
    this.level = level;
    return data;
}

public int getWidth() {
    return width;
}

public int setWidth(int width) {
    if (width <= 0) {
        throw new IllegalArgumentException();
    }
    int data = this.width;
    this.width = width;
    return data;
}

public double getLowerBound() {
    return level - (width / 2);
}

public double getUpperBound() {
    return level + (width / 2);
}

public double map(Hounsfield f) {

    int hounsfieldUnitVal = f.get();
    System.out.println(hounsfieldUnitVal);
    if (hounsfieldUnitVal < getLowerBound()) {
        return 0;
    }
    if (hounsfieldUnitVal > getUpperBound()) {
        return 1;
    }
    return (hounsfieldUnitVal - getLowerBound()) / width;
}

0 个答案:

没有答案