Skip to content

Commit

Permalink
Merge branch 'LogInTest' of https://github.com/CSC207-UofT/course-pro…
Browse files Browse the repository at this point in the history
…ject-bugwatcher_group036 into york5

� Conflicts:
�	src/main/java/LogIn/LogInEntity/UserList.java
  • Loading branch information
zhumengzhiren committed Dec 5, 2021
2 parents dbc9e90 + f9757af commit 6a91ac9
Show file tree
Hide file tree
Showing 6 changed files with 188 additions and 12 deletions.
12 changes: 0 additions & 12 deletions src/main/java/LogIn/LogInEntity/UserList.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,24 +9,12 @@
*/
public class UserList implements Serializable {

/**
* Initialize a new user list.
*/
private final Map<String, User> users = new HashMap<>();

/**
*
* @param user Add a new user to the user list.
*/
public void add(User user) {
users.put(user.getUsername(), user);
}

/**
*
* @param username The username of the user.
* @return Get the user according to the username.
*/
public User getUser(String username) {
return users.get(username);
}
Expand Down
29 changes: 29 additions & 0 deletions src/test/java/LogIn/Entity/UserListTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package LogIn.Entity;

import LogIn.LogInEntity.User;
import LogIn.LogInEntity.UserList;

import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.*;

import java.util.HashMap;

public class UserListTest {
UserList userList = new UserList();
User user = new User("Allen", "1007224576");

@Test
public void testAdd() {
userList.add(user);
User user0 = userList.getUser("Allen");
assertEquals(user0.getUsername(), "Allen");
}

@Test
public void testGetUser() {
userList.add(user);
User user0 = new User("Jame", "123456");
User user1 = userList.getUser("Jame");
assertEquals(user0.getUsername(), "Jame");
}
}
4 changes: 4 additions & 0 deletions src/test/java/LogIn/Entity/UserReadWriterTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
package LogIn.Entity;

public class UserReadWriterTest {
}
99 changes: 99 additions & 0 deletions src/test/java/LogIn/Entity/UserStaticsTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
package LogIn.Entity;

import LogIn.LogInEntity.UserStatistics;
import org.junit.jupiter.api.Test;

import java.net.PortUnreachableException;

import static org.junit.jupiter.api.Assertions.*;


public class UserStaticsTest {
UserStatistics statistics = new UserStatistics("Allen");

@Test
public void testInitialization() {
assertEquals(statistics.getPlayerId(), "Allen");

}

@Test
public void testGetStats() {
int[] stats = statistics.getStats();
assertEquals(stats[0], 0);
assertEquals(stats.length, 7);
}

@Test
public void testPVPWin() {
statistics.PVPWin();
int[] stats = statistics.getStats();
assertEquals(stats[0], 1);
assertEquals(stats[1], 0);
assertEquals(stats[5], 100);
assertEquals(stats.length, 7);

}

@Test
public void testPVEWin() {
statistics.PVEWin();
int[] stats = statistics.getStats();
assertEquals(stats[0], 0);
assertEquals(stats[1], 1);
assertEquals(stats[5], 70);
assertEquals(stats.length, 7);

}

@Test
public void testDrawCard() {
statistics.drawCard(10);
int[] stats = statistics.getStats();
assertEquals(stats[0], 0);
assertEquals(stats[0], 0);
assertEquals(stats[5], 10);
assertEquals(stats.length, 7);
}

@Test
public void testPlayCard() {
int[] stats = statistics.getStats();
assertEquals(stats[6], 0);
statistics.playCard("red 5");
assertEquals(stats[2], 1);
assertEquals(stats[3], 0);
assertEquals(stats[5], 2);
assertEquals(stats[6], 1);
assertEquals(stats.length, 7);
statistics.playCard("red +2");
assertEquals(stats[2], 2);
assertEquals(stats[3], 1);
assertEquals(stats[5], 7);
assertEquals(stats[6], 1);
assertEquals(stats.length, 7);

}

@Test
public void testCheckExp() {
statistics.checkExp();
int[] stats = statistics.getStats();
assertEquals(stats[0], 0);
assertEquals(stats[6], 1);
assertEquals(stats.length, 7);
}

@Test
public void testGetPlayerId() {
String id = statistics.getPlayerId();
assertEquals(id, "Allen");
}

@Test
public void testToString() {
String s = statistics.toString();
assertEquals(s, "PVP win count: 0\nPVE win count: 0\ntotal card played: 0\n" +
"total function card played: 0\ntotal card drawn: 0\nexp: 0\nplayer level: 0\n");
}
}
52 changes: 52 additions & 0 deletions src/test/java/LogIn/Entity/UserTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
package LogIn.Entity;

import LogIn.LogInEntity.User;
import LogIn.LogInEntity.UserStatistics;
import org.junit.jupiter.api.Test;

import static org.junit.jupiter.api.Assertions.*;

public class UserTest {
User user = new User("Allen", "123456");
User user0 = new User("Jack", "010814");

@Test
public void testInitialization() {
String username = user.getUsername();
assertEquals(username, "Allen");
}

@Test
public void testPasswordMatches() {
assertFalse(user.passwordMatches("010814"));
assertTrue(user.passwordMatches("123456"));
}

@Test
public void testGetUsername() {
assertEquals(user.getUsername(), "Allen");
assertEquals(user0.getUsername(), "Jack");
}

@Test
public void testToString() {
String s = user.toString();
assertEquals(s, "Username: Allen, Password: 123456");
}

@Test
public void testGetUserStatics() {
UserStatistics userStat = user.getUserStatistics();
int[] stat = userStat.getStats();
assertEquals(stat.length, 7);

}

@Test
public void testSetUserStatics() {
UserStatistics userStat = new UserStatistics("Allen");
user.setUserStatistics(userStat);
assertEquals(user.getUserStatistics(), userStat);

}
}
4 changes: 4 additions & 0 deletions src/test/java/LogIn/UseCase/LogInUseCaseTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
package LogIn.UseCase;

public class LogInUseCaseTest {
}

0 comments on commit 6a91ac9

Please sign in to comment.