|
@ -1,8 +1,12 @@ |
|
|
|
|
|
import org.json.simple.JSONArray; |
|
|
|
|
|
import org.json.simple.JSONObject; |
|
|
import org.junit.jupiter.api.Test; |
|
|
import org.junit.jupiter.api.Test; |
|
|
import src.GameField; |
|
|
import src.GameField; |
|
|
import src.MainFrame; |
|
|
import src.MainFrame; |
|
|
import src.Model; |
|
|
import src.Model; |
|
|
|
|
|
|
|
|
|
|
|
import java.util.Iterator; |
|
|
|
|
|
|
|
|
import static org.junit.jupiter.api.Assertions.*; |
|
|
import static org.junit.jupiter.api.Assertions.*; |
|
|
|
|
|
|
|
|
public class ModelTest extends MainFrame { |
|
|
public class ModelTest extends MainFrame { |
|
@ -202,4 +206,30 @@ public class ModelTest extends MainFrame { |
|
|
@Test |
|
|
@Test |
|
|
public void test_showAllGames() { |
|
|
public void test_showAllGames() { |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
|
|
public void test_modelToJson() { |
|
|
|
|
|
|
|
|
|
|
|
//mock |
|
|
|
|
|
GameField gameField = new GameField(360); |
|
|
|
|
|
for (int i = 0, k = 13; i < 9; i++) { |
|
|
|
|
|
for (int j = 0, l = 17; j < 9; j++) { |
|
|
|
|
|
gameField.setValue(i, j, (i*l+j*k)%9); |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
Model model = new Model(gameField); |
|
|
|
|
|
|
|
|
|
|
|
//test |
|
|
|
|
|
JSONObject jsonObject = model.modelToJson(); |
|
|
|
|
|
JSONArray values = (JSONArray) jsonObject.get("values"); |
|
|
|
|
|
Iterator iterator = values.iterator(); |
|
|
|
|
|
while (iterator.hasNext()) { |
|
|
|
|
|
JSONObject next = (JSONObject) iterator.next(); |
|
|
|
|
|
int x = (int) next.get("x"); |
|
|
|
|
|
int y = (int) next.get("y"); |
|
|
|
|
|
int value = (int) next.get("value"); |
|
|
|
|
|
int r = (x*13+y*17)%9; |
|
|
|
|
|
assertEquals(r, value, "x:"+x+", y:"+y+"="+value+"-->"+r+"?"); |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
} |
|
|
} |