私は、リストを作成するために使用される1つのクラスを持っています。これはテストの結果である:To DoタスクにID番号を割り当てる方法は?
-----------------------------------------
TESTS - CONSTRUCTOR 1
-----------------------------------------
Construction todo ("description 1")... ➤ [⍡] - 1) description 1() **(expected result in the test)**
id: 1 (System.out.println of the id in the test class)
➤ [⍡] - 1) description 1 **(result)**
OK **(the test is ok)**
Construction todo ("")... OK
Construction todo (null)... OK
------------------------------------------
TESTS - CONSTRUCTOR 2
------------------------------------------
Construction todo (23/08/2016, "description 2")... id : 2 **(here id is 2)**
➤ 23/08/2016 [⍡] - 2) description 2
OK
Construction todo (null, "description 3")... id : 3 **(here id is 3)**
OK
Construction todo (01/01/2016, "xxx")... OK
Construction todo (10/09/2016, "")... OK
Construction todo (10/09/2016, null)... OK
------------------------------------------
TESTS - CONSTRUCTOR 3
------------------------------------------
Construction todo (15/07/2016, "description 4", Todo.HIGH_IMPORTANCE)... **expected** : ➤ 15/07/2016 [⍥] - 4) description 4
**but i got** : ➤ 15/07/2016 [⍥] - 5) description 4 **(on this line the id is 5 instead of 4)**
id: 5 **(System.out.println of the id in test class)**
ERROR **(thats why i have here error)**
Construction todo (null, "description 5", Todo.MEDIUM_IMPORTANCE... id : 6 **(System.out.println in the test class)**
ERROR
Construction todo (01/01/2016, "xxx", Todo.HIGH_IMPORTANCE)... OK
Construction todo (10/09/2016, "", Todo.HIGH_IMPORTANCE)... OK
Construction todo (10/09/2016, null, Todo.HIGH_IMPORTANCE)... OK
------------------------
TESTS - GETTERS
------------------------
GET ID... OK
GET Date creation... OK
GET Dead line... OK
GET Description... OK
GET Description... OK
IS COMPLETED... OK
------------------------
TESTS - SETTERS
------------------------
SET Dead line... OK
SET Completed... OK
SET Level importance... OK
SET Level importance invalid... OK
Checking if the level of importance has not changed... **we expect** : ➤ [⍨] - 5) description 5
**printed result**: ➤ [⍨] - 6) description 5 **(here id is not good, need to be 5)**
ERROR
SET Description... OK
SET Description empty... OK
Checking that the description has not been changed... **we expect** : ➤ 15/07/2016 [⍥] - 4) description 4
**printed result**: ➤ 15/07/2016 [⍥] - 5) description 4
ERROR **(THAT'S WHY ERROR)**
SET Description null... OK
Checking that the description has not been changed... **we expect** : ➤ 15/07/2016 [⍥] - 4) description 4
**printed result**: ➤ 15/07/2016 [⍥] - 5) description 4
ERROR
----------------------------------------------------
TESTS - METHOD OBTENIR GETING LAST ID ASSUMED
----------------------------------------------------
Last id assumed = 5... **id printed is 7**... ERROR
---------------------------------------
TESTS - METHOD HAS PRIORITY OVER
---------------------------------------
Test 1... OK
Test 2... OK
Test 3... OK
Test 4... OK
Test 5... OK
Test 6... OK
Test 7... OK
Test 8... OK
Test 9... OK
Test 10... OK
そして、これは私のクラスである:isMoreRecent()
public class Todo {
public static final int HIGH_IMPORTANCE = 1;
public static final int MEDIUM_IMPORTANCE = 2;
public static final int LOW_IMPORTANCE = 3;
private static int lastIdAssumed = 0;
private Date dateCreation;
private Date deadline;
private String description;
private int levelImportance;
private boolean completed;
private int id;
public Todo(String description) throws TodoInvalideException{
if (description != null && description.length() != 0) {
this.description = description;
} else {
throw new TodoInvalideException();
}
this.dateCreation = Date.todayDate();
this.deadline = null;
this.levelImportance = LOW_IMPORTANCE;
this.completed = false;
lastIdAssumed = lastIdAssumed + 1;
this.id = lastIdAssumed;
}
public Todo(Date deadline, String description)throws TodoInvalideException, DateInvalideException {
this(description);
if (deadline != null && dateCreation.estPlusRecente(deadline)){
throw new TodoInvalideException();
}
this.deadline = deadline;
}
public Todo(Date deadline, String description, int levelImportance)throws TodoInvalideException, DateInvalideException{
this(deadline, description);
if (levelImportance == HIGH_IMPORTANCE || levelImportance == MEDIUM_IMPORTANCE
|| levelImportance == LOW_IMPORTANCE) {
this.levelImportance = levelImportance;
} else {
throw new TodoInvalideException();
}
}
//GETTERS (6)
public Date getDateCreation(){
return dateCreation;
}
public Date getDeadline(){
return deadline;
}
public String getDescription(){
return description;
}
public boolean isCompleted(){
return completed;
}
public int getLevelImportance(){
return levelImportance;
}
public int getId(){
return id;
}
//SETTERS (4)
public void setDeadline(Date deadline){
this.deadline = deadline;
}
public void setDescription(String description) throws TodoInvalideException {
if (description != null && description.length() != 0) {
this.description = description;
} else {
throw new TodoInvalideException();
}
}
public void setCompleted(boolean completed){
this.completed = completed;
}
public void setLevelImportance(int levelImportance) throws TodoInvalideException {
if (levelImportance == HIGH_IMPORTANCE || levelImportance == MEDIUM_IMPORTANCE
|| levelImportance == LOW_IMPORTANCE) {
this.levelImportance = levelImportance;
} else {
throw new TodoInvalideException();
}
}
public boolean hasPriorityOver (Todo anotherTodo) throws TodoInvalideException, DateInvalideException {
boolean priorityTodo = false;
if (this.deadline == null && anotherTodo.deadline == null) {
if (this.levelImportance < anotherTodo.levelImportance) {
priorityTodo = true;
}
} else if (this.deadline == null && anotherTodo.deadline != null) {
priorityTodo = false;
} else if (this.deadline != null && anotherTodo.deadline == null) {
priorityTodo = true;
}
if(this.deadline != null && anotherTodo.deadline != null) {
if (anotherTodo.deadline.isMoreRecent(this.deadline)) {
priorityTodo = true;
}else{
priorityTodo = false;
}
if (this.deadline.isEquals(anotherTodo.deadline)) {
if (this.levelImportance < anotherTodo.levelImportance) {
priorityTodo = true;
}else{
priorityTodo = false;
}
}
}
return priorityTodo;
}
public String toString() {
String [] tab = {"", "[\u2365]", "[\u2368]", "[\u2361]"};
String s = "";
if (completed) {
s = s + "\u2714";
} else {
s = s + "\u27A4";
}
if (deadline == null) {
s = s + " ";
} else {
s = s + " " + deadline;
}
s = s + " " + tab[levelImportance];
s = s + " - " + id + ") " + description;
return s;
}
public static int getingLastIdAssumed() {
return lastIdAssumed;
}
}
方法、isEquals()とDate.todayDate()他のクラスという名前の日であります。 ありがとうございます!
質問はありますか?ありますか –
私のテストでは間違ったIDを取得しています –
おそらく、おそらくテストドライバのどこかに作成された予期せぬToDoクラスがあります。 'id'が' lastIdAssumed'(インクリメントされている)から割り当てられているという事実は示唆的です。私は問題が出力に表示されているものと仮定していますが、@ RamanShrivastavaが示唆しているように、質問がより直接的に記述されていれば簡単になります。 – KevinO