-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #5 from cuappdev/cindy/factories
added factories
- Loading branch information
Showing
8 changed files
with
226 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,6 +8,7 @@ | |
|
||
# IntelliJ | ||
.idea/ | ||
.idea | ||
*.iml | ||
*.iws | ||
*.ipr | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
60 changes: 60 additions & 0 deletions
60
src/test/java/com/example/allin/AllInApplicationTests.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
package com.example.allin; | ||
|
||
import org.junit.jupiter.api.Test; | ||
import static org.mockito.Mockito.mock; | ||
import com.example.allin.contract.Contract; | ||
import com.example.allin.contract.util.ContractGenerator; | ||
import com.example.allin.contract.Rarity; | ||
import com.example.allin.player.Player; | ||
import com.example.allin.user.User; | ||
import com.example.allin.playerData.PlayerDataRepo; | ||
import com.example.allin.data.PlayerFactory; | ||
import com.example.allin.data.UserFactory; | ||
|
||
|
||
|
||
class AllInApplicationTests { | ||
@Test | ||
public void testGenerateContract() { | ||
|
||
PlayerDataRepo playerDataRepo = mock(PlayerDataRepo.class); | ||
ContractGenerator contractGenerator = new ContractGenerator(playerDataRepo); | ||
|
||
System.out.println("Testing ContractGenerator.generateContract()"); | ||
System.out.println("Common Probability Threshold: " + ContractGenerator.COMMON_PROBABILITY_THRESHOLD); | ||
System.out.println("Rare Probability Threshold: " + ContractGenerator.RARE_PROBABILITY_THRESHOLD); | ||
System.out.println("Epic Probability Threshold: " + ContractGenerator.EPIC_PROBABILITY_THRESHOLD); | ||
System.out.println("Legendary Probability Threshold: " + ContractGenerator.LEGENDARY_PROBABILITY_THRESHOLD + "\n\n"); | ||
|
||
ContractGenerator.generateBounds(); | ||
|
||
System.out.println("Printing Probability and Payout Ranges\n"); | ||
System.out.println("Common Probability: [" + ContractGenerator.COMMON_PROB_LOWER_BOUND + ", " + ContractGenerator.COMMON_PROB_UPPER_BOUND + "]"); | ||
System.out.println("Common Payout: [" + ContractGenerator.COMMON_PAYOUT_LOWER_BOUND + ", " + ContractGenerator.COMMON_PAYOUT_UPPER_BOUND + "]\n"); | ||
System.out.println("Rare Probability: [" + ContractGenerator.RARE_PROB_LOWER_BOUND + ", " + ContractGenerator.RARE_PROB_UPPER_BOUND + "]"); | ||
System.out.println("Rare Payout: [" + ContractGenerator.RARE_PAYOUT_LOWER_BOUND + ", " + ContractGenerator.RARE_PAYOUT_UPPER_BOUND + "]\n"); | ||
System.out.println("Epic Probability: [" + ContractGenerator.EPIC_PROB_LOWER_BOUND + ", " + ContractGenerator.EPIC_PROB_UPPER_BOUND + "]"); | ||
System.out.println("Epic Payout: [" + ContractGenerator.EPIC_PAYOUT_LOWER_BOUND + ", " + ContractGenerator.EPIC_PAYOUT_UPPER_BOUND + "]\n"); | ||
System.out.println("Legendary Probability: [" + ContractGenerator.LEGENDARY_PROB_LOWER_BOUND + ", " + ContractGenerator.LEGENDARY_PROB_UPPER_BOUND + "]"); | ||
System.out.println("Legendary Payout: [" + ContractGenerator.LEGENDARY_PAYOUT_LOWER_BOUND + ", " + ContractGenerator.LEGENDARY_PAYOUT_UPPER_BOUND + "]\n"); | ||
|
||
double common_alpha = (ContractGenerator.COMMON_PROB_UPPER_BOUND + ContractGenerator.COMMON_PROB_LOWER_BOUND) * (ContractGenerator.COMMON_PAYOUT_UPPER_BOUND + ContractGenerator.COMMON_PAYOUT_LOWER_BOUND) / 4.0; | ||
double rare_alpha = (ContractGenerator.RARE_PROB_UPPER_BOUND + ContractGenerator.RARE_PROB_LOWER_BOUND) * (ContractGenerator.RARE_PAYOUT_UPPER_BOUND + ContractGenerator.RARE_PAYOUT_LOWER_BOUND) / 4.0; | ||
double epic_alpha = (ContractGenerator.EPIC_PROB_UPPER_BOUND + ContractGenerator.EPIC_PROB_LOWER_BOUND) * (ContractGenerator.EPIC_PAYOUT_UPPER_BOUND + ContractGenerator.EPIC_PAYOUT_LOWER_BOUND) / 4.0; | ||
double legendary_alpha = (ContractGenerator.LEGENDARY_PROB_UPPER_BOUND + ContractGenerator.LEGENDARY_PROB_LOWER_BOUND) * (ContractGenerator.LEGENDARY_PAYOUT_UPPER_BOUND + ContractGenerator.LEGENDARY_PAYOUT_LOWER_BOUND) / 4.0; | ||
|
||
System.out.println("Alphas:"); | ||
System.out.println("Common: " + common_alpha); | ||
System.out.println("Rare: " + rare_alpha); | ||
System.out.println("Epic: " + epic_alpha); | ||
System.out.println("Legendary: " + legendary_alpha + "\n"); | ||
|
||
System.out.println("Generating a Contract\n"); | ||
|
||
User user = UserFactory.createRandomUser(); | ||
Player player = PlayerFactory.createFakePlayer(); | ||
Contract contract = contractGenerator.generateContract(user, player, 100.0, Rarity.Common); | ||
System.out.println("Contract: " + contract.toString()); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
package com.example.allin.data; | ||
import com.example.allin.contract.OpposingTeam; | ||
import com.example.allin.contract.Rarity; | ||
import com.example.allin.user.User; | ||
import com.example.allin.player.Player; | ||
import com.example.allin.contract.Contract; | ||
import com.example.allin.contract.Event; | ||
import com.example.allin.data.PlayerFactory; | ||
import com.github.javafaker.Faker; | ||
|
||
import java.time.LocalDate; | ||
import java.util.Random; | ||
|
||
//needs tests | ||
public class ContractFactory { | ||
private final Faker faker = new Faker(); | ||
private final Random random = new Random(); | ||
|
||
private final PlayerFactory playerFactory = new PlayerFactory(); | ||
private final UserFactory userFactory = new UserFactory(); | ||
|
||
|
||
public Contract createRandomContract() { | ||
Player player = playerFactory.createFakePlayer(); | ||
User owner = userFactory.createRandomUser(); | ||
Double buyPrice = faker.number().randomDouble(2, 100, 5000); // Random buy price between 100 and 5000 | ||
Rarity rarity = Rarity.getRandomRarity(); // Random rarity | ||
OpposingTeam opposingTeam = OpposingTeam.getRandomOpposingTeam(); | ||
String opposingTeamImage = faker.internet().avatar(); // Random image URL | ||
Event event = Event.getRandomEvent(); | ||
Integer eventThreshold = faker.number().numberBetween(1, 100); // Random event threshold between 1 and 100 | ||
LocalDate creationTime = LocalDate.now().minusDays(faker.number().numberBetween(1, 365)); // Within the past year | ||
Double value = faker.number().randomDouble(2, 100, 5000); // Random value between 100 and 5000 | ||
Boolean expired = faker.bool().bool(); | ||
Boolean forSale = faker.bool().bool(); | ||
Double sellPrice = forSale ? faker.number().randomDouble(2, 100, 5000) : null; // If for sale, random sell price | ||
|
||
return new Contract(player, owner, buyPrice, rarity, opposingTeam, opposingTeamImage, event, eventThreshold, | ||
creationTime, value, expired, forSale, sellPrice); | ||
} | ||
} | ||
|
32 changes: 32 additions & 0 deletions
32
src/test/java/com/example/allin/data/PlayerDataFactory.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
package com.example.allin.data; | ||
import com.example.allin.player.Player; | ||
import com.example.allin.contract.OpposingTeam; | ||
import com.example.allin.playerData.PlayerData; | ||
import com.github.javafaker.Faker; | ||
|
||
import java.time.LocalDate; | ||
import java.util.Random; | ||
|
||
//need to test this | ||
public class PlayerDataFactory { | ||
private static final Faker faker = new Faker(); | ||
private final Random random = new Random(); | ||
|
||
public static PlayerData createRandomPlayerData(Player player, OpposingTeam opposingTeam) { | ||
LocalDate gameDate = LocalDate.now().minusDays(faker.number().numberBetween(1, 365)); // Random date within the past year | ||
Integer points = faker.number().numberBetween(0, 50); // Points scored | ||
Integer minutes = faker.number().numberBetween(10, 48); // Minutes played | ||
Integer fieldGoals = faker.number().numberBetween(0, points / 2); // Field goals made (estimate based on points) | ||
Integer threePointers = faker.number().numberBetween(0, fieldGoals / 3); // Three-pointers made | ||
Integer freeThrows = faker.number().numberBetween(0, points - fieldGoals * 2); // Free throws | ||
Integer rebounds = faker.number().numberBetween(0, 15); | ||
Integer assists = faker.number().numberBetween(0, 15); | ||
Integer steals = faker.number().numberBetween(0, 5); | ||
Integer blocks = faker.number().numberBetween(0, 5); | ||
Integer turnovers = faker.number().numberBetween(0, 7); | ||
Integer fouls = faker.number().numberBetween(0, 5); | ||
|
||
return new PlayerData(player, gameDate, opposingTeam, points, minutes, fieldGoals, threePointers, freeThrows, | ||
rebounds, assists, steals, blocks, turnovers, fouls); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
package com.example.allin.data; | ||
import com.example.allin.player.Player; | ||
import com.example.allin.player.Position; | ||
import com.github.javafaker.Faker; | ||
import java.util.Random; | ||
|
||
|
||
public class PlayerFactory { | ||
private static final Faker faker = new Faker(); | ||
private static final Random random = new Random(); | ||
|
||
|
||
public static Player createFakePlayer() { | ||
String firstName = faker.name().firstName(); | ||
String lastName = faker.name().lastName(); | ||
Position[] positions = generateRandomPositions(); | ||
Integer number = faker.number().numberBetween(1, 99); // Jersey numbers typically range from 1-99 | ||
String height = generateRandomHeight(); | ||
Integer weight = faker.number().numberBetween(150, 250); // Weight in pounds, adjustable as needed | ||
String hometown = faker.address().city() + ", " + faker.address().state(); | ||
String highSchool = faker.educator().secondarySchool(); | ||
return new Player(firstName, lastName, positions, number, height, weight, hometown, highSchool); | ||
} | ||
|
||
private static Position[] generateRandomPositions() { | ||
Position[] allPositions = Position.values(); | ||
int count = random.nextInt(2) + 1; // Players can have 1 or 2 positions | ||
Position[] positions = new Position[count]; | ||
for (int i = 0; i < count; i++) { | ||
positions[i] = allPositions[random.nextInt(allPositions.length)]; | ||
} | ||
return positions; | ||
} | ||
|
||
private static String generateRandomHeight() { | ||
int feet = faker.number().numberBetween(5, 7); // Heights between 5 and 7 feet | ||
int inches = faker.number().numberBetween(0, 11); | ||
return feet + "'" + inches + "\""; | ||
} | ||
|
||
} |
29 changes: 29 additions & 0 deletions
29
src/test/java/com/example/allin/data/TransactionFactory.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
package com.example.allin.data; | ||
import com.example.allin.transaction.Transaction; | ||
import com.example.allin.user.User; | ||
import com.example.allin.contract.Contract; | ||
import com.example.allin.data.ContractFactory; | ||
import com.github.javafaker.Faker; | ||
|
||
import java.time.LocalDate; | ||
|
||
//needs tests | ||
public class TransactionFactory { | ||
private final Faker faker = new Faker(); | ||
private final UserFactory userFactory = new UserFactory(); | ||
private final ContractFactory contractFactory = new ContractFactory(); | ||
|
||
public Transaction createRandomTransaction() { | ||
User seller = userFactory.createRandomUser(); | ||
User buyer = userFactory.createRandomUser(); | ||
while (buyer.equals(seller)) { // Ensure buyer and seller are different | ||
buyer = userFactory.createRandomUser(); | ||
} | ||
|
||
Contract contract = contractFactory.createRandomContract(); | ||
LocalDate transactionDate = LocalDate.now().minusDays(faker.number().numberBetween(1, 365)); // Date within the past year | ||
Double price = faker.number().randomDouble(2, 100, 10000); // Random price between 100 and 10000 | ||
|
||
return new Transaction(seller, buyer, contract, transactionDate, price); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
package com.example.allin.data; | ||
import com.example.allin.user.User; | ||
import com.github.javafaker.Faker; | ||
|
||
public class UserFactory { | ||
private static final Faker faker = new Faker(); | ||
|
||
public static User createRandomUser() { | ||
String username = faker.name().username(); | ||
String email = faker.internet().emailAddress(); | ||
String image = faker.internet().avatar(); | ||
Double balance = faker.number().randomDouble(2, 10, 1000); | ||
|
||
return new User(username, email, image, balance); | ||
} | ||
} |