Search in sources :

Example 16 with Query

use of me.staartvin.statz.database.datatype.Query in project Statz by Staartvin.

the class QueryTest method testMultipleConflictingQueries2.

@Test
public void testMultipleConflictingQueries2() {
    Query queryA = StatzUtil.makeQuery("UUID", "3657b9cc-2518-4265-ad69-323e11286ce2", "mob", "COW", "value", 100);
    Query queryB = StatzUtil.makeQuery("uuid", "3657b9cc-2518-4265-ad69-323e11286ce2", "mob", "COW", "value", 100);
    Query queryC = StatzUtil.makeQuery("uuid", "3657b9cc-2518-4265-ad69-323e11286ce2", "mob", "COW", "value", 200);
    Query queryD = StatzUtil.makeQuery("uuid", "3657b9cc-2518-4265-ad69-323e11286ce2", "mob", "COW", "value", 500);
    Query queryE = StatzUtil.makeQuery("uuid", "3657b9cc-2518-4265-ad69-323e11286ce2", "mob", "COW", "value", 100);
    Query queryF = StatzUtil.makeQuery("uuid", "3657b9cc-2518-4265-ad69-323e11286ce2", "mob", "PIG", "value", 100);
    List<Query> conflictingQueries = new ArrayList<>();
    conflictingQueries.add(queryB);
    conflictingQueries.add(queryC);
    conflictingQueries.add(queryD);
    conflictingQueries.add(queryE);
    conflictingQueries.add(queryF);
    Query nonConflictingQuery = queryA.resolveConflicts(conflictingQueries);
    Assert.assertEquals(1000, nonConflictingQuery.getValue(), 0);
}
Also used : Query(me.staartvin.statz.database.datatype.Query) ArrayList(java.util.ArrayList) Test(org.junit.Test)

Example 17 with Query

use of me.staartvin.statz.database.datatype.Query in project Statz by Staartvin.

the class QueryTest method testConflictingQuery2.

// Same number of columns and UUIDs are the same, ignoring value column
@Test
public void testConflictingQuery2() {
    Query queryA = StatzUtil.makeQuery("UUID", "3657b9cc-2518-4265-ad69-323e11286ce2", "value", 5);
    Query queryB = StatzUtil.makeQuery("uuid", "3657b9cc-2518-4265-ad69-323e11286ce2", "value", 5498);
    checkConflict(queryA, queryB, true);
}
Also used : Query(me.staartvin.statz.database.datatype.Query) Test(org.junit.Test)

Example 18 with Query

use of me.staartvin.statz.database.datatype.Query in project Statz by Staartvin.

the class QueryTest method testRobustnessResolveConflictingQueries.

// Queries are not conflicting, so cannot resolve.
@Test(expected = IllegalArgumentException.class)
public void testRobustnessResolveConflictingQueries() {
    Query queryA = StatzUtil.makeQuery("UUID", "3657b9cc-2518-4265-ad69-323e11286ce2", "mob", "COW", "value", 100);
    Query queryB = StatzUtil.makeQuery("uuid", "3657b9cc-2518-4265-ad69-323e11286ce2", "mob", "Chicken", "value", -6);
    queryA.resolveConflict(queryB).getValue();
}
Also used : Query(me.staartvin.statz.database.datatype.Query) Test(org.junit.Test)

Example 19 with Query

use of me.staartvin.statz.database.datatype.Query in project Statz by Staartvin.

the class PlayerInfoTest method testResolvePlayerInfo5.

// Test two conflicting (of same statType) and two non conflicting (of another statType, that conflict with each
// other).
@Test
public void testResolvePlayerInfo5() {
    UUID uuid = UUID.fromString("3657b9cc-2518-4265-ad69-323e11286ce2");
    PlayerStat statType = PlayerStat.ARROWS_SHOT;
    PlayerStat statType2 = PlayerStat.KILLS_MOBS;
    PlayerInfo playerInfo = new PlayerInfo(uuid);
    PlayerInfo playerInfo2 = new PlayerInfo(uuid);
    Query queryA = StatzUtil.makeQuery("UUID", uuid, "World", "worldName1", "value", 5);
    Query queryB = StatzUtil.makeQuery("UUID", uuid, "World", "worldName1", "value", 6);
    Query queryC = StatzUtil.makeQuery("UUID", uuid, "World", "worldName2", "value", 8);
    Query queryD = StatzUtil.makeQuery("UUID", uuid, "World", "worldName2", "value", 45);
    Query queryE = StatzUtil.makeQuery("UUID", uuid, "World", "worldName3", "value", 100);
    playerInfo.addRow(statType, queryA);
    playerInfo2.addRow(statType, queryB);
    playerInfo2.addRow(statType2, queryC);
    playerInfo.addRow(statType2, queryD);
    playerInfo.addRow(statType, queryE);
    PlayerInfo nonConflictingPlayerInfo = playerInfo.resolveConflicts(playerInfo2);
    // Verify the number of rows
    Assert.assertEquals(2, nonConflictingPlayerInfo.getNumberOfRows(statType));
    Assert.assertEquals(1, nonConflictingPlayerInfo.getNumberOfRows(statType2));
    // Verify the number of statistics stored.
    Assert.assertEquals(2, nonConflictingPlayerInfo.getNumberOfStatistics());
    // Verify that value is correct
    Assert.assertEquals(111, nonConflictingPlayerInfo.getTotalValue(statType), 0);
    Assert.assertEquals(53, nonConflictingPlayerInfo.getTotalValue(statType2), 0);
}
Also used : Query(me.staartvin.statz.database.datatype.Query) PlayerInfo(me.staartvin.statz.datamanager.player.PlayerInfo) PlayerStat(me.staartvin.statz.datamanager.player.PlayerStat) UUID(java.util.UUID) Test(org.junit.Test)

Example 20 with Query

use of me.staartvin.statz.database.datatype.Query in project Statz by Staartvin.

the class PlayerInfoTest method testResolvePlayerInfo2.

// Test with two conflicting and one non-conflicting query
@Test
public void testResolvePlayerInfo2() {
    UUID uuid = UUID.fromString("3657b9cc-2518-4265-ad69-323e11286ce2");
    PlayerStat statType = PlayerStat.ARROWS_SHOT;
    PlayerInfo playerInfo = new PlayerInfo(uuid);
    PlayerInfo playerInfo2 = new PlayerInfo(uuid);
    Query queryA = StatzUtil.makeQuery("UUID", uuid, "World", "worldName1", "value", 5);
    Query queryB = StatzUtil.makeQuery("UUID", uuid, "World", "worldName1", "value", 6);
    Query queryC = StatzUtil.makeQuery("UUID", uuid, "World", "worldName2", "value", 8);
    playerInfo.addRow(statType, queryA);
    playerInfo2.addRow(statType, queryB);
    playerInfo2.addRow(statType, queryC);
    PlayerInfo nonConflictingPlayerInfo = playerInfo.resolveConflicts(playerInfo2);
    // Verify that there is only 1 row
    Assert.assertEquals(2, nonConflictingPlayerInfo.getNumberOfRows(statType));
    // Verify that there is only 1 statistic stored
    Assert.assertEquals(1, nonConflictingPlayerInfo.getNumberOfStatistics());
    // Verify that value is correct
    Assert.assertEquals(19, nonConflictingPlayerInfo.getTotalValue(statType), 0);
}
Also used : Query(me.staartvin.statz.database.datatype.Query) PlayerInfo(me.staartvin.statz.datamanager.player.PlayerInfo) PlayerStat(me.staartvin.statz.datamanager.player.PlayerStat) UUID(java.util.UUID) Test(org.junit.Test)

Aggregations

Query (me.staartvin.statz.database.datatype.Query)44 Test (org.junit.Test)25 PlayerInfo (me.staartvin.statz.datamanager.player.PlayerInfo)13 PlayerStat (me.staartvin.statz.datamanager.player.PlayerStat)11 ArrayList (java.util.ArrayList)8 UUID (java.util.UUID)6 RowRequirement (me.staartvin.statz.database.datatype.RowRequirement)4 HashMap (java.util.HashMap)2 Material (org.bukkit.Material)2 Player (org.bukkit.entity.Player)2 Inventory (org.bukkit.inventory.Inventory)2 ItemStack (org.bukkit.inventory.ItemStack)2 ItemMeta (org.bukkit.inventory.meta.ItemMeta)2 BufferedWriter (java.io.BufferedWriter)1 File (java.io.File)1 FileWriter (java.io.FileWriter)1 IOException (java.io.IOException)1 Date (java.util.Date)1 Map (java.util.Map)1 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)1