bandwagoner
This commit is contained in:
24
bandwagoner/.exercism/config.json
Normal file
24
bandwagoner/.exercism/config.json
Normal file
@@ -0,0 +1,24 @@
|
||||
{
|
||||
"authors": [
|
||||
"lpil"
|
||||
],
|
||||
"files": {
|
||||
"solution": [
|
||||
"src/bandwagoner.gleam"
|
||||
],
|
||||
"test": [
|
||||
"test/bandwagoner_test.gleam"
|
||||
],
|
||||
"exemplar": [
|
||||
".meta/example.gleam"
|
||||
],
|
||||
"invalidator": [
|
||||
"gleam.toml",
|
||||
"manifest.toml"
|
||||
]
|
||||
},
|
||||
"forked_from": [
|
||||
"fsharp/bandwagoner"
|
||||
],
|
||||
"blurb": "Learn about labelled fields by keeping a history of basketball statistics"
|
||||
}
|
||||
1
bandwagoner/.exercism/metadata.json
Normal file
1
bandwagoner/.exercism/metadata.json
Normal file
@@ -0,0 +1 @@
|
||||
{"track":"gleam","exercise":"bandwagoner","id":"cb4f65e8957045f3a56d4433769e0a33","url":"https://exercism.org/tracks/gleam/exercises/bandwagoner","handle":"fw353qwgs","is_requester":true,"auto_approve":false}
|
||||
4
bandwagoner/.gitignore
vendored
Normal file
4
bandwagoner/.gitignore
vendored
Normal file
@@ -0,0 +1,4 @@
|
||||
*.beam
|
||||
*.ez
|
||||
build
|
||||
erl_crash.dump
|
||||
32
bandwagoner/HELP.md
Normal file
32
bandwagoner/HELP.md
Normal file
@@ -0,0 +1,32 @@
|
||||
# Help
|
||||
|
||||
## Running the tests
|
||||
|
||||
To run the tests, run the command `gleam test` from within the exercise directory.
|
||||
|
||||
## Submitting your solution
|
||||
|
||||
You can submit your solution using the `exercism submit src/bandwagoner.gleam` command.
|
||||
This command will upload your solution to the Exercism website and print the solution page's URL.
|
||||
|
||||
It's possible to submit an incomplete solution which allows you to:
|
||||
|
||||
- See how others have completed the exercise
|
||||
- Request help from a mentor
|
||||
|
||||
## Need to get help?
|
||||
|
||||
If you'd like help solving the exercise, check the following pages:
|
||||
|
||||
- The [Gleam track's documentation](https://exercism.org/docs/tracks/gleam)
|
||||
- The [Gleam track's programming category on the forum](https://forum.exercism.org/c/programming/gleam)
|
||||
- [Exercism's programming category on the forum](https://forum.exercism.org/c/programming/5)
|
||||
- The [Frequently Asked Questions](https://exercism.org/docs/using/faqs)
|
||||
|
||||
Should those resources not suffice, you could submit your (incomplete) solution to request mentoring.
|
||||
|
||||
To get help if you're having trouble, you can use one of the following resources:
|
||||
|
||||
- [gleam.run](https://gleam.run/documentation/) is the gleam official documentation.
|
||||
- [Discord](https://discord.gg/Fm8Pwmy) is the discord channel.
|
||||
- [StackOverflow](https://stackoverflow.com/questions/tagged/gleam) can be used to search for your problem and see if it has been answered already. You can also ask and answer questions.
|
||||
15
bandwagoner/HINTS.md
Normal file
15
bandwagoner/HINTS.md
Normal file
@@ -0,0 +1,15 @@
|
||||
# Hints
|
||||
|
||||
## 5. Replace the coach
|
||||
|
||||
- The record update syntax can be used to create a copy of a record but with one or more fields having a new value.
|
||||
|
||||
## 6. Check for same team
|
||||
|
||||
- Records have built-in structural equality, which means that records that have the same values are equal.
|
||||
|
||||
## 7. Check if you should root for a team
|
||||
|
||||
- The best way to execute logic based on the team's value is to use a case expression.
|
||||
- If you want to add a condition to a pattern, you can use a guard.
|
||||
- Pattern matching works for records within records.
|
||||
202
bandwagoner/README.md
Normal file
202
bandwagoner/README.md
Normal file
@@ -0,0 +1,202 @@
|
||||
# Bandwagoner
|
||||
|
||||
Welcome to Bandwagoner on Exercism's Gleam Track.
|
||||
If you need help running the tests or submitting your code, check out `HELP.md`.
|
||||
If you get stuck on the exercise, check out `HINTS.md`, but try and solve it without using those first :)
|
||||
|
||||
## Introduction
|
||||
|
||||
## Labelled Fields
|
||||
|
||||
When a custom type variant holds data it is called a record, and each contained value resides in a _field_.
|
||||
|
||||
```gleam
|
||||
pub type Rectangle {
|
||||
Rectangle(
|
||||
Float, // The first field
|
||||
Float, // The second field
|
||||
)
|
||||
}
|
||||
```
|
||||
|
||||
To aid readability Gleam allows fields to be labelled with a name.
|
||||
|
||||
```gleam
|
||||
pub type Rectangle {
|
||||
Rectangle(
|
||||
width: Float,
|
||||
height: Float,
|
||||
)
|
||||
}
|
||||
```
|
||||
|
||||
Labels can be used to give arguments in any order to the constructor of a record.
|
||||
|
||||
```gleam
|
||||
let a = Rectangle(height: 10.0, width: 20.0)
|
||||
let b = Rectangle(width: 20.0, height: 10.0)
|
||||
|
||||
a == b
|
||||
// -> True
|
||||
```
|
||||
|
||||
When a custom type has only one variant then the `.label` accessor syntax can be used to get the fields of a record.
|
||||
|
||||
```gleam
|
||||
let rect = Rectangle(height: 10.0, width: 20.0)
|
||||
|
||||
rect.height // -> 10.0
|
||||
rect.width // -> 20.0
|
||||
```
|
||||
|
||||
The record update syntax can be used when a custom type has a single variant to create a new record from an existing one, but with some of the fields replaced with new values.
|
||||
|
||||
```gleam
|
||||
let rect = Rectangle(height: 10.0, width: 20.0)
|
||||
let tall_rect = Rectangle(..rect, height: 50.0)
|
||||
|
||||
tall_rect.height // -> 50.0
|
||||
tall_rect.width // -> 20.0
|
||||
```
|
||||
|
||||
Labels can also be used when pattern matching to extract values from records.
|
||||
|
||||
```gleam
|
||||
pub fn is_tall(rect: Rectangle) {
|
||||
case rect {
|
||||
Rectangle(height: h, width: _) if h >. 20.0 -> True
|
||||
_ -> False
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
If we only want to match on some of the fields we can use the spread operator `..` to ignore any remaining fields.
|
||||
|
||||
```gleam
|
||||
pub fn is_tall(rect: Rectangle) {
|
||||
case rect {
|
||||
Rectangle(height: h, ..) if h >. 20.0 -> True
|
||||
_ -> False
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
## Instructions
|
||||
|
||||
In this exercise you're a big sports fan and you've just discovered a passion for NBA basketball. Being new to NBA basketball, you're doing a deep dive into NBA history, keeping track of teams, coaches, their win/loss stats, and comparing them against each other.
|
||||
|
||||
As you don't yet have a favorite team, you'll also be developing an algorithm to figure out whether to root for a particular team.
|
||||
|
||||
You have seven tasks to help you develop your proprietary _root-for-a-team_ algorithm.
|
||||
|
||||
## 1. Define the model
|
||||
|
||||
Define the `Coach` record with the following two fields:
|
||||
|
||||
- `name`: the coach's name, of type `String`.
|
||||
- `former_player`: indicates if the coach was a former player, of type `Bool`.
|
||||
|
||||
Define the `Stats` record with the following two fields:
|
||||
|
||||
- `wins`: the number of wins, of type `Int`.
|
||||
- `losses`: the number of losses, of type `Int`.
|
||||
|
||||
Define the `Team` record with the following three fields:
|
||||
|
||||
- `name`: the team's name, of type `String`.
|
||||
- `coach`: the team's coach, of type `Coach`.
|
||||
- `stats`: the team's stats, of type `Stats`.
|
||||
|
||||
## 2. Create a team's coach
|
||||
|
||||
Implement the `create_coach` function that takes the coach name and its former player status as parameters, and returns its `Coach` record:
|
||||
|
||||
```gleam
|
||||
create_coach("Larry Bird", True)
|
||||
// -> Coach(name: "Larry Bird", former_player: True)
|
||||
```
|
||||
|
||||
## 3. Create a team's stats
|
||||
|
||||
Implement the `create_stats` function that takes the number of wins and the number losses as parameters, and returns its `Stats` record:
|
||||
|
||||
```gleam
|
||||
create_stats(58, 24)
|
||||
// -> Stats(wins: 58, losses: 24)
|
||||
```
|
||||
|
||||
## 4. Create a team
|
||||
|
||||
Implement the `create_team` function that takes the team name, coach and record as parameters, and returns its `Team` record:
|
||||
|
||||
```gleam
|
||||
let coach = create_coach("Larry Bird", True)
|
||||
let stats = create_stats(58, 24)
|
||||
create_team("Indiana Pacers", coach, stats)
|
||||
// -> Team(
|
||||
// name: "Indiana Pacers",
|
||||
// coach: Coach(name: "Larry Bird", FormerPlayer = True),
|
||||
// stats: Stats(wins: 58, losses: 24),
|
||||
// )
|
||||
```
|
||||
|
||||
## 5. Replace the coach
|
||||
|
||||
NBA owners being impatient, you found that bad team results would often lead to the coach being replaced. Implement the `replace_coach` function that takes the team and its new coach as parameters, and returns the team but with the new coach:
|
||||
|
||||
```gleam
|
||||
let coach = create_coach("Larry Bird", True)
|
||||
let record = create_stats(58, 24)
|
||||
let team = create_team("Indiana Pacers", coach, record)
|
||||
|
||||
let new_coach = create_coach("Isiah Thomas", True)
|
||||
replace_coach(team, new_coach)
|
||||
// -> Team(
|
||||
// name: "Indiana Pacers",
|
||||
// coach: Coach(name: "Isiah Thomas", FormerPlayer = True),
|
||||
// stats: Stats(wins: 58, losses: 24),
|
||||
// )
|
||||
```
|
||||
|
||||
## 6. Check for same team
|
||||
|
||||
While digging into stats, you're keeping lists of teams and their records. Sometimes, you get things wrong and there are duplicate entries on your list. Implement the `is_same_team` function that takes two teams and returns `True` if they are the same team, otherwise, return `False`:
|
||||
|
||||
```gleam
|
||||
let pacers_coach = create_coach("Larry Bird", True)
|
||||
let pacers_stats = create_stats(58, 24)
|
||||
let pacers_team = create_team("Indiana Pacers", pacers_coach, pacers_stats)
|
||||
|
||||
let lakers_coach = create_coach("Del Harris", False)
|
||||
let lakers_stats = create_stats(61, 21)
|
||||
let lakers_team = create_team("LA Lakers", lakers_coach, lakers_stats)
|
||||
|
||||
is_same_team(pacers_team, lakers_team)
|
||||
// -> False
|
||||
```
|
||||
|
||||
## 7. Check if you should root for a team
|
||||
|
||||
Having looked at many teams and matches, you've come up with an algorithm. If one of the following is True, you root for that team:
|
||||
|
||||
- The coach's name is "Gregg Popovich"
|
||||
- The coach is a former player
|
||||
- The team's name is the "Chicago Bulls"
|
||||
- The team has won 60 or more games
|
||||
- The team has more losses than wins
|
||||
|
||||
Implement the `root_for_team` function that takes a team and returns `True` if you should root for that team, otherwise, return `False`:
|
||||
|
||||
```gleam
|
||||
let spurs_coach = create_coach("Gregg Popovich", False)
|
||||
let spurs_stats = create_stats(56, 26)
|
||||
let spurs_team = create_team("San Antonio Spurs", spurs_coach, spurs_stats)
|
||||
root_for_team(spurs_team)
|
||||
// -> True
|
||||
```
|
||||
|
||||
## Source
|
||||
|
||||
### Created by
|
||||
|
||||
- @lpil
|
||||
14
bandwagoner/gleam.toml
Normal file
14
bandwagoner/gleam.toml
Normal file
@@ -0,0 +1,14 @@
|
||||
name = "bandwagoner"
|
||||
version = "0.1.0"
|
||||
|
||||
[dependencies]
|
||||
gleam_otp = "~> 0.7 or ~> 1.0"
|
||||
gleam_stdlib = ">= 0.54.0 or ~> 1.0"
|
||||
simplifile = "~> 1.0"
|
||||
gleam_erlang = ">= 0.25.0 and < 1.0.0"
|
||||
gleam_yielder = ">= 1.1.0 and < 2.0.0"
|
||||
gleam_regexp = ">= 1.1.0 and < 2.0.0"
|
||||
gleam_deque = ">= 1.0.0 and < 2.0.0"
|
||||
|
||||
[dev-dependencies]
|
||||
exercism_test_runner = "~> 1.9"
|
||||
31
bandwagoner/manifest.toml
Normal file
31
bandwagoner/manifest.toml
Normal file
@@ -0,0 +1,31 @@
|
||||
# This file was generated by Gleam
|
||||
# You typically do not need to edit this file
|
||||
|
||||
packages = [
|
||||
{ name = "argv", version = "1.0.2", build_tools = ["gleam"], requirements = [], otp_app = "argv", source = "hex", outer_checksum = "BA1FF0929525DEBA1CE67256E5ADF77A7CDDFE729E3E3F57A5BDCAA031DED09D" },
|
||||
{ name = "exercism_test_runner", version = "1.9.0", build_tools = ["gleam"], requirements = ["argv", "gap", "glance", "gleam_community_ansi", "gleam_erlang", "gleam_json", "gleam_stdlib", "simplifile"], otp_app = "exercism_test_runner", source = "hex", outer_checksum = "0B17BB25F2FF1E60266467C24FE0CA04005410306AA05E9A4B41B1852D72865C" },
|
||||
{ name = "filepath", version = "1.1.0", build_tools = ["gleam"], requirements = ["gleam_stdlib"], otp_app = "filepath", source = "hex", outer_checksum = "67A6D15FB39EEB69DD31F8C145BB5A421790581BD6AA14B33D64D5A55DBD6587" },
|
||||
{ name = "gap", version = "1.1.3", build_tools = ["gleam"], requirements = ["gleam_community_ansi", "gleam_stdlib"], otp_app = "gap", source = "hex", outer_checksum = "6EF5E3B523FDFBC317E9EA28D5163EE04744A97C007106F90207569789612291" },
|
||||
{ name = "glance", version = "1.1.0", build_tools = ["gleam"], requirements = ["gleam_stdlib", "glexer"], otp_app = "glance", source = "hex", outer_checksum = "E155BA1A787FD11827048355021C0390D2FE9A518485526F631A9D472858CC6D" },
|
||||
{ name = "gleam_community_ansi", version = "1.4.3", build_tools = ["gleam"], requirements = ["gleam_community_colour", "gleam_regexp", "gleam_stdlib"], otp_app = "gleam_community_ansi", source = "hex", outer_checksum = "8A62AE9CC6EA65BEA630D95016D6C07E4F9973565FA3D0DE68DC4200D8E0DD27" },
|
||||
{ name = "gleam_community_colour", version = "2.0.0", build_tools = ["gleam"], requirements = ["gleam_json", "gleam_stdlib"], otp_app = "gleam_community_colour", source = "hex", outer_checksum = "FDD6AC62C6EC8506C005949A4FCEF032038191D5EAAEC3C9A203CD53AE956ACA" },
|
||||
{ name = "gleam_deque", version = "1.0.0", build_tools = ["gleam"], requirements = ["gleam_stdlib"], otp_app = "gleam_deque", source = "hex", outer_checksum = "64D77068931338CF0D0CB5D37522C3E3CCA7CB7D6C5BACB41648B519CC0133C7" },
|
||||
{ name = "gleam_erlang", version = "0.34.0", build_tools = ["gleam"], requirements = ["gleam_stdlib"], otp_app = "gleam_erlang", source = "hex", outer_checksum = "0C38F2A128BAA0CEF17C3000BD2097EB80634E239CE31A86400C4416A5D0FDCC" },
|
||||
{ name = "gleam_json", version = "2.3.0", build_tools = ["gleam"], requirements = ["gleam_stdlib"], otp_app = "gleam_json", source = "hex", outer_checksum = "C55C5C2B318533A8072D221C5E06E5A75711C129E420DD1CE463342106012E5D" },
|
||||
{ name = "gleam_otp", version = "0.16.1", build_tools = ["gleam"], requirements = ["gleam_erlang", "gleam_stdlib"], otp_app = "gleam_otp", source = "hex", outer_checksum = "50DA1539FC8E8FA09924EB36A67A2BBB0AD6B27BCDED5A7EF627057CF69D035E" },
|
||||
{ name = "gleam_regexp", version = "1.1.0", build_tools = ["gleam"], requirements = ["gleam_stdlib"], otp_app = "gleam_regexp", source = "hex", outer_checksum = "7F5E0C0BBEB3C58E57C9CB05FA9002F970C85AD4A63BA1E55CBCB35C15809179" },
|
||||
{ name = "gleam_stdlib", version = "0.55.0", build_tools = ["gleam"], requirements = [], otp_app = "gleam_stdlib", source = "hex", outer_checksum = "32D8F4AE03771516950047813A9E359249BD9FBA5C33463FDB7B953D6F8E896B" },
|
||||
{ name = "gleam_yielder", version = "1.1.0", build_tools = ["gleam"], requirements = ["gleam_stdlib"], otp_app = "gleam_yielder", source = "hex", outer_checksum = "8E4E4ECFA7982859F430C57F549200C7749823C106759F4A19A78AEA6687717A" },
|
||||
{ name = "glexer", version = "2.2.1", build_tools = ["gleam"], requirements = ["gleam_stdlib"], otp_app = "glexer", source = "hex", outer_checksum = "5C235CBDF4DA5203AD5EAB1D6D8B456ED8162C5424FE2309CFFB7EF438B7C269" },
|
||||
{ name = "simplifile", version = "1.7.0", build_tools = ["gleam"], requirements = ["filepath", "gleam_stdlib"], otp_app = "simplifile", source = "hex", outer_checksum = "1D5DFA3A2F9319EC85825F6ED88B8E449F381B0D55A62F5E61424E748E7DDEB0" },
|
||||
]
|
||||
|
||||
[requirements]
|
||||
exercism_test_runner = { version = "~> 1.9" }
|
||||
gleam_deque = { version = ">= 1.0.0 and < 2.0.0" }
|
||||
gleam_erlang = { version = ">= 0.25.0 and < 1.0.0" }
|
||||
gleam_otp = { version = "~> 0.7 or ~> 1.0" }
|
||||
gleam_regexp = { version = ">= 1.1.0 and < 2.0.0" }
|
||||
gleam_stdlib = { version = ">= 0.54.0 or ~> 1.0" }
|
||||
gleam_yielder = { version = ">= 1.1.0 and < 2.0.0" }
|
||||
simplifile = { version = "~> 1.0" }
|
||||
45
bandwagoner/src/bandwagoner.gleam
Normal file
45
bandwagoner/src/bandwagoner.gleam
Normal file
@@ -0,0 +1,45 @@
|
||||
pub type Coach {
|
||||
Coach(name: String, former_player: Bool)
|
||||
}
|
||||
|
||||
pub type Stats {
|
||||
Stats(wins: Int, losses: Int)
|
||||
}
|
||||
|
||||
pub type Team {
|
||||
Team(name: String, coach: Coach, stats: Stats)
|
||||
}
|
||||
|
||||
pub fn create_coach(name: String, former_player: Bool) -> Coach {
|
||||
Coach(name:, former_player:)
|
||||
}
|
||||
|
||||
pub fn create_stats(wins: Int, losses: Int) -> Stats {
|
||||
Stats(wins:, losses:)
|
||||
}
|
||||
|
||||
pub fn create_team(name: String, coach: Coach, stats: Stats) -> Team {
|
||||
Team(name:, coach:, stats:)
|
||||
}
|
||||
|
||||
pub fn replace_coach(team: Team, coach: Coach) -> Team {
|
||||
Team(..team, coach:)
|
||||
}
|
||||
|
||||
pub fn is_same_team(home_team: Team, away_team: Team) -> Bool {
|
||||
home_team == away_team
|
||||
}
|
||||
|
||||
pub fn root_for_team(team: Team) -> Bool {
|
||||
let correct_coach = team.coach.name == "Gregg Popovich"
|
||||
let coach_is_former_player = team.coach.former_player
|
||||
let correct_team = team.name == "Chicago Bulls"
|
||||
let sixty_or_more_wins = team.stats.wins >= 60
|
||||
let underdogs = team.stats.losses > team.stats.wins
|
||||
|
||||
correct_coach
|
||||
|| coach_is_former_player
|
||||
|| correct_team
|
||||
|| sixty_or_more_wins
|
||||
|| underdogs
|
||||
}
|
||||
237
bandwagoner/test/bandwagoner_test.gleam
Normal file
237
bandwagoner/test/bandwagoner_test.gleam
Normal file
@@ -0,0 +1,237 @@
|
||||
import bandwagoner.{Coach, Stats, Team}
|
||||
import exercism/should
|
||||
import exercism/test_runner
|
||||
|
||||
pub fn main() {
|
||||
test_runner.main()
|
||||
}
|
||||
|
||||
pub fn create_coach_that_was_a_former_player_test() {
|
||||
bandwagoner.create_coach("Steve Kerr", True)
|
||||
|> should.equal(Coach(name: "Steve Kerr", former_player: True))
|
||||
}
|
||||
|
||||
pub fn create_coach_that_wasnt_a_former_player_test() {
|
||||
bandwagoner.create_coach("Erik Spoelstra", False)
|
||||
|> should.equal(Coach(name: "Erik Spoelstra", former_player: False))
|
||||
}
|
||||
|
||||
pub fn create_stats_for_winning_team_test() {
|
||||
bandwagoner.create_stats(55, 27)
|
||||
|> should.equal(Stats(wins: 55, losses: 27))
|
||||
}
|
||||
|
||||
pub fn create_stats_for_losing_team_test() {
|
||||
bandwagoner.create_stats(39, 43)
|
||||
|> should.equal(Stats(wins: 39, losses: 43))
|
||||
}
|
||||
|
||||
pub fn create_stats_for_all_time_season_record_test() {
|
||||
bandwagoner.create_stats(73, 9)
|
||||
|> should.equal(Stats(wins: 73, losses: 9))
|
||||
}
|
||||
|
||||
pub fn create_60s_team_test() {
|
||||
let coach = bandwagoner.create_coach("Red Auerbach", False)
|
||||
let stats = bandwagoner.create_stats(58, 22)
|
||||
let team = bandwagoner.create_team("Boston Celtics", coach, stats)
|
||||
|
||||
team
|
||||
|> should.equal(Team(
|
||||
name: "Boston Celtics",
|
||||
coach: Coach(name: "Red Auerbach", former_player: False),
|
||||
stats: Stats(wins: 58, losses: 22),
|
||||
))
|
||||
}
|
||||
|
||||
pub fn create_2010s_team_test() {
|
||||
let coach = bandwagoner.create_coach("Rick Carlisle", False)
|
||||
let stats = bandwagoner.create_stats(57, 25)
|
||||
let team = bandwagoner.create_team("Dallas Mavericks", coach, stats)
|
||||
|
||||
team
|
||||
|> should.equal(Team(
|
||||
name: "Dallas Mavericks",
|
||||
coach: Coach(name: "Rick Carlisle", former_player: False),
|
||||
stats: Stats(wins: 57, losses: 25),
|
||||
))
|
||||
}
|
||||
|
||||
pub fn replace_coach_mid_season_test() {
|
||||
let old_coach = bandwagoner.create_coach("Willis Reed", True)
|
||||
let new_coach = bandwagoner.create_coach("Red Holzman", True)
|
||||
let stats = bandwagoner.create_stats(6, 8)
|
||||
let team = bandwagoner.create_team("New York Knicks", old_coach, stats)
|
||||
|
||||
bandwagoner.replace_coach(team, new_coach)
|
||||
|> should.equal(Team(
|
||||
name: "New York Knicks",
|
||||
coach: Coach(name: "Red Holzman", former_player: True),
|
||||
stats: Stats(wins: 6, losses: 8),
|
||||
))
|
||||
}
|
||||
|
||||
pub fn replace_coach_after_season_test() {
|
||||
let old_coach = bandwagoner.create_coach("Rudy Tomjanovich", True)
|
||||
let new_coach = bandwagoner.create_coach("Jeff van Gundy", True)
|
||||
let stats = bandwagoner.create_stats(43, 39)
|
||||
let team = bandwagoner.create_team("Houston Rockets", old_coach, stats)
|
||||
|
||||
bandwagoner.replace_coach(team, new_coach)
|
||||
|> should.equal(Team(
|
||||
name: "Houston Rockets",
|
||||
coach: Coach(name: "Jeff van Gundy", former_player: True),
|
||||
stats: Stats(wins: 43, losses: 39),
|
||||
))
|
||||
}
|
||||
|
||||
pub fn same_team_is_duplicate_test() {
|
||||
let coach = bandwagoner.create_coach("Pat Riley", True)
|
||||
let stats = bandwagoner.create_stats(57, 25)
|
||||
let team = bandwagoner.create_team("Los Angeles Lakers", coach, stats)
|
||||
|
||||
let assert True = bandwagoner.is_same_team(team, team)
|
||||
}
|
||||
|
||||
pub fn same_team_with_different_stats_is_not_a_duplicate_test() {
|
||||
let coach = bandwagoner.create_coach("Pat Riley", True)
|
||||
let stats = bandwagoner.create_stats(57, 25)
|
||||
let team = bandwagoner.create_team("Los Angeles Lakers", coach, stats)
|
||||
|
||||
let new_stats = bandwagoner.create_stats(62, 20)
|
||||
let team_with_different_stats =
|
||||
bandwagoner.create_team("Los Angeles Lakers", coach, new_stats)
|
||||
|
||||
let assert False = bandwagoner.is_same_team(team, team_with_different_stats)
|
||||
}
|
||||
|
||||
pub fn same_team_with_different_coach_is_not_a_duplicate_test() {
|
||||
let coach = bandwagoner.create_coach("Pat Riley", True)
|
||||
let stats = bandwagoner.create_stats(33, 39)
|
||||
let team = bandwagoner.create_team("Los Angeles Lakers", coach, stats)
|
||||
|
||||
let new_coach = bandwagoner.create_coach("John Kundla", True)
|
||||
let team_with_different_coach =
|
||||
bandwagoner.create_team("Los Angeles Lakers", new_coach, stats)
|
||||
|
||||
let assert False = bandwagoner.is_same_team(team, team_with_different_coach)
|
||||
}
|
||||
|
||||
pub fn different_team_with_same_coach_and_stats_test() {
|
||||
let stats = bandwagoner.create_stats(0, 0)
|
||||
let coach = bandwagoner.create_coach("Mike d'Antoni", True)
|
||||
|
||||
let team = bandwagoner.create_team("Denver Nuggets", coach, stats)
|
||||
let other_team = bandwagoner.create_team("Phoenix Suns", coach, stats)
|
||||
|
||||
let assert False = bandwagoner.is_same_team(team, other_team)
|
||||
}
|
||||
|
||||
pub fn different_team_with_different_coach_and_stats_test() {
|
||||
let stats = bandwagoner.create_stats(42, 40)
|
||||
let coach = bandwagoner.create_coach("Dave Joerger", True)
|
||||
let team = bandwagoner.create_team("Memphis Grizzlies", coach, stats)
|
||||
|
||||
let other_stats = bandwagoner.create_stats(63, 19)
|
||||
let other_coach = bandwagoner.create_coach("Larry Costello", True)
|
||||
let other_team =
|
||||
bandwagoner.create_team("Milwaukee Bucks", other_coach, other_stats)
|
||||
|
||||
let assert False = bandwagoner.is_same_team(team, other_team)
|
||||
}
|
||||
|
||||
pub fn root_for_team_with_favorite_coach_and_winning_stats_test() {
|
||||
let stats = bandwagoner.create_stats(60, 22)
|
||||
let coach = bandwagoner.create_coach("Gregg Popovich", False)
|
||||
let team = bandwagoner.create_team("San Antonio Spurs", coach, stats)
|
||||
|
||||
let assert True = bandwagoner.root_for_team(team)
|
||||
}
|
||||
|
||||
pub fn root_for_team_with_favorite_coach_and_losing_stats_test() {
|
||||
let stats = bandwagoner.create_stats(17, 47)
|
||||
let coach = bandwagoner.create_coach("Gregg Popovich", False)
|
||||
let team = bandwagoner.create_team("San Antonio Spurs", coach, stats)
|
||||
|
||||
let assert True = bandwagoner.root_for_team(team)
|
||||
}
|
||||
|
||||
pub fn root_for_team_with_coach_is_former_player_and_winning_stats_test() {
|
||||
let stats = bandwagoner.create_stats(49, 33)
|
||||
let coach = bandwagoner.create_coach("Jack Ramsay", True)
|
||||
let team = bandwagoner.create_team("Portland Trail Blazers", coach, stats)
|
||||
|
||||
let assert True = bandwagoner.root_for_team(team)
|
||||
}
|
||||
|
||||
pub fn root_for_team_with_coach_is_former_player_and_losing_stats_test() {
|
||||
let stats = bandwagoner.create_stats(0, 7)
|
||||
let coach = bandwagoner.create_coach("Jack Ramsay", True)
|
||||
let team = bandwagoner.create_team("Indiana Pacers", coach, stats)
|
||||
|
||||
let assert True = bandwagoner.root_for_team(team)
|
||||
}
|
||||
|
||||
pub fn root_for_favorite_team_and_winning_stats_test() {
|
||||
let stats = bandwagoner.create_stats(61, 21)
|
||||
let coach = bandwagoner.create_coach("Phil Jackson", True)
|
||||
let team = bandwagoner.create_team("Chicago Bulls", coach, stats)
|
||||
|
||||
let assert True = bandwagoner.root_for_team(team)
|
||||
}
|
||||
|
||||
pub fn root_for_favorite_team_and_losing_stats_test() {
|
||||
let stats = bandwagoner.create_stats(24, 58)
|
||||
let coach = bandwagoner.create_coach("Dick Motta", False)
|
||||
let team = bandwagoner.create_team("Chicago Bulls", coach, stats)
|
||||
|
||||
let assert True = bandwagoner.root_for_team(team)
|
||||
}
|
||||
|
||||
pub fn root_for_team_with_sixty_or_more_wins_and_former_player_coach_test() {
|
||||
let stats = bandwagoner.create_stats(65, 17)
|
||||
let coach = bandwagoner.create_coach("Billy Cunningham", True)
|
||||
let team = bandwagoner.create_team("Philadelphia 76'ers", coach, stats)
|
||||
|
||||
let assert True = bandwagoner.root_for_team(team)
|
||||
}
|
||||
|
||||
pub fn root_for_team_with_sixty_or_more_wins_and_non_former_player_coach_test() {
|
||||
let stats = bandwagoner.create_stats(60, 22)
|
||||
let coach = bandwagoner.create_coach("Mike Budenholzer", False)
|
||||
let team = bandwagoner.create_team("Milwaukee Bucks", coach, stats)
|
||||
|
||||
let assert True = bandwagoner.root_for_team(team)
|
||||
}
|
||||
|
||||
pub fn root_for_team_with_more_losses_than_wins_and_former_player_coach_test() {
|
||||
let stats = bandwagoner.create_stats(40, 42)
|
||||
let coach = bandwagoner.create_coach("Wes Unseld", True)
|
||||
let team = bandwagoner.create_team("Washington Bullets", coach, stats)
|
||||
|
||||
let assert True = bandwagoner.root_for_team(team)
|
||||
}
|
||||
|
||||
pub fn root_for_team_with_more_losses_than_wins_and_non_former_player_coach_test() {
|
||||
let stats = bandwagoner.create_stats(29, 43)
|
||||
let coach = bandwagoner.create_coach("Kenny Atkinson", False)
|
||||
let team = bandwagoner.create_team("Rochester Royals", coach, stats)
|
||||
|
||||
let assert True = bandwagoner.root_for_team(team)
|
||||
}
|
||||
|
||||
pub fn root_for_team_chicago_bulls_test() {
|
||||
let stats = bandwagoner.create_stats(50, 13)
|
||||
let coach = bandwagoner.create_coach("Billy Donovan", False)
|
||||
let team = bandwagoner.create_team("Chicago Bulls", coach, stats)
|
||||
|
||||
let assert True = bandwagoner.root_for_team(team)
|
||||
}
|
||||
|
||||
pub fn dont_root_for_team_not_matching_criteria_test() {
|
||||
let stats = bandwagoner.create_stats(51, 31)
|
||||
let coach = bandwagoner.create_coach("Frank Layden", False)
|
||||
let team = bandwagoner.create_team("Utah Jazz", coach, stats)
|
||||
|
||||
let assert False = bandwagoner.root_for_team(team)
|
||||
}
|
||||
Reference in New Issue
Block a user