Skip to content

Commit

Permalink
sorry (#6)
Browse files Browse the repository at this point in the history
* sorry

* chat is not my good friend

* overloaded contract factory with getting a user from database and passing in a user
  • Loading branch information
cindy-x-liang authored Nov 11, 2024
1 parent dc1e8dc commit 60ad0a0
Show file tree
Hide file tree
Showing 9 changed files with 122 additions and 180 deletions.
1 change: 1 addition & 0 deletions src/test/java/com/appdev/allin/AllInApplicationTests.java
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,7 @@ public void testGenerateContract() {
"Akron, OH",
"St. Vincent-St. Mary",
"src/main/resources/static/images/players/default.jpg");

Contract contract = contractGenerator.generateContract(user, player, 100.0, Rarity.Common);
System.out.println("Contract: " + contract.toString());
}
Expand Down
74 changes: 74 additions & 0 deletions src/test/java/com/appdev/allin/data/ContractFactory.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
package com.appdev.allin.data;
import com.appdev.allin.contract.OpposingTeam;
import com.appdev.allin.contract.Rarity;
import com.appdev.allin.user.User;
import com.appdev.allin.player.Player;
import com.appdev.allin.contract.Contract;
import com.appdev.allin.contract.Event;
import com.appdev.allin.data.PlayerFactory;
import com.appdev.allin.user.UserRepo;
import com.appdev.allin.user.UserService;
import com.github.javafaker.Faker;

import java.time.LocalDate;
import java.util.List;
import java.util.Random;
import org.springframework.beans.factory.annotation.Autowired;

//needs tests
public class ContractFactory {
private static final Faker faker = new Faker();
private final Random random = new Random();

private static final PlayerFactory playerFactory = new PlayerFactory();

private final UserFactory userFactory = new UserFactory();

@Autowired UserService userService;




public Contract createRandomContract(User owner) {
Player player = playerFactory.createFakePlayer();
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);
}
public Contract createRandomContract() throws Exception {
Player player = playerFactory.createFakePlayer();
List<User> users = userService.getAllUsers();
User owner;
if (users.isEmpty()){
throw new Exception("No initialized users!");
}else{
owner = users.get(0);
}
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);
}
}

Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package com.example.allin.data;
import com.example.allin.player.Player;
import com.example.allin.contract.OpposingTeam;
import com.example.allin.playerData.PlayerData;
package com.appdev.allin.data;
import com.appdev.allin.player.Player;
import com.appdev.allin.contract.OpposingTeam;
import com.appdev.allin.playerData.PlayerData;
import com.github.javafaker.Faker;

import java.time.LocalDate;
Expand Down
57 changes: 32 additions & 25 deletions src/test/java/com/appdev/allin/data/PlayerFactory.java
Original file line number Diff line number Diff line change
@@ -1,34 +1,41 @@
package com.appdev.allin.data;

import com.appdev.allin.player.Player;
import com.appdev.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 fakeTemplate() {
return new Player(
"LeBron",
"James",
new Position[] {Position.Center},
23,
"6'9",
250,
"Akron, OH",
"St. Vincent-St. Mary",
"src/main/resources/static/images/players/default.jpg");
}

public static Player fake() {
// return a player with random values
return new Player(
"LeBron",
"James",
new Position[] {Position.Center},
23,
"6'9",
250,
"Akron, OH",
"St. Vincent-St. Mary",
"src/main/resources/static/images/players/default.jpg");
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 + "\"";
}

}
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
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;
package com.appdev.allin.data;
import com.appdev.allin.transaction.Transaction;
import com.appdev.allin.user.User;
import com.appdev.allin.contract.Contract;
import com.appdev.allin.data.PlayerFactory;
import com.appdev.allin.player.Player;
import com.appdev.allin.data.ContractFactory;
import com.github.javafaker.Faker;

import java.time.LocalDate;
Expand All @@ -19,8 +21,9 @@ public Transaction createRandomTransaction() {
while (buyer.equals(seller)) { // Ensure buyer and seller are different
buyer = userFactory.createRandomUser();
}
Player player = PlayerFactory.createFakePlayer();

Contract contract = contractFactory.createRandomContract();
Contract contract = contractFactory.createRandomContract(seller);
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

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
package com.example.allin.data;
import com.example.allin.user.User;
package com.appdev.allin.data;
import com.appdev.allin.user.User;
import com.github.javafaker.Faker;

public class UserFactory {
Expand Down
60 changes: 0 additions & 60 deletions src/test/java/com/example/allin/AllInApplicationTests.java

This file was deleted.

42 changes: 0 additions & 42 deletions src/test/java/com/example/allin/data/ContractFactory.java

This file was deleted.

41 changes: 0 additions & 41 deletions src/test/java/com/example/allin/data/PlayerFactory.java

This file was deleted.

0 comments on commit 60ad0a0

Please sign in to comment.