matches

package
v0.0.0-...-e9ad2ff Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 29, 2023 License: MIT Imports: 2 Imported by: 0

Documentation

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Match

type Match struct {
	// contains filtered or unexported fields
}

Match ist ein Datentyp, der das Ergebnis eines Sportspiels speichern soll.

func NewMatch

func NewMatch(home, visitors string, score Score) Match

NewMatch erzeugt ein neues Match-Objekt mit den übergebenen Werten.

func (Match) HomeName

func (m Match) HomeName() string

HomeName gibt den Namen der Heimmannschaft zurück. Falls die Heimmannschaft gewonnen hat, wird der Name in Sternchen gesetzt.

Example
m1 := NewMatch("FC Freiburg", "Borussia Bremen", NewScore(1, 2))
m2 := NewMatch("FC Freiburg", "Borussia Bremen", NewScore(2, 1))
m3 := NewMatch("FC Freiburg", "Borussia Bremen", NewScore(2, 2))

fmt.Println(m1.HomeName())
fmt.Println(m2.HomeName())
fmt.Println(m3.HomeName())
Output:

FC Freiburg
*FC Freiburg*
FC Freiburg

func (Match) String

func (m Match) String() string

String gibt das Match als String in der Form "FC Freiburg - *Borussia Bremen*: 1:2" zurück. Dabei soll immer der Name der Heimmannschaft zuerst stehen und der Name des Gewinners in Sternchen gesetzt werden.

Example
m := NewMatch("FC Freiburg", "Borussia Bremen", NewScore(1, 2))

fmt.Println(m)
Output:

FC Freiburg - *Borussia Bremen*: 1:2

func (Match) VisitorName

func (m Match) VisitorName() string

VisitorName gibt den Namen der Auswärtsmannschaft zurück. Falls die Auswärtsmannschaft gewonnen hat, wird der Name in Sternchen gesetzt.

Example
m1 := NewMatch("FC Freiburg", "Borussia Bremen", NewScore(1, 2))
m2 := NewMatch("FC Freiburg", "Borussia Bremen", NewScore(2, 1))
m3 := NewMatch("FC Freiburg", "Borussia Bremen", NewScore(2, 2))

fmt.Println(m1.VisitorName())
fmt.Println(m2.VisitorName())
fmt.Println(m3.VisitorName())
Output:

*Borussia Bremen*
Borussia Bremen
Borussia Bremen

func (Match) Winner

func (m Match) Winner() string

Winner gibt den Namen des Gewinners zurück. Wenn es keinen Gewinner gibt, wird "unentschieden" zurückgegeben.

Example
m1 := NewMatch("FC Freiburg", "Borussia Bremen", NewScore(1, 2))
m2 := NewMatch("FC Freiburg", "Borussia Bremen", NewScore(2, 1))
m3 := NewMatch("FC Freiburg", "Borussia Bremen", NewScore(2, 2))

fmt.Println(m1.Winner())
fmt.Println(m2.Winner())
fmt.Println(m3.Winner())
Output:

Borussia Bremen
FC Freiburg
unentschieden

type MatchList

type MatchList struct {
	// contains filtered or unexported fields
}

MatchList ist ein Datentyp für eine Liste von Spielergebnissen.

func NewMatchList

func NewMatchList(matches ...Match) MatchList

NewMatchList erzeugt eine neue MatchList mit den übergebenen Matches.

func (*MatchList) Add

func (ml *MatchList) Add(m Match)

Add fügt ein Match zur MatchList hinzu.

Example
ml := NewMatchList()

// Spieltag 1
ml.Add(NewMatch("Fortuna Fürth", "FC Frankfurt", NewScore(1, 2)))
ml.Add(NewMatch("Dynamo Dortmund", "Concordia Cottbus", NewScore(3, 3)))

// Spieltag 2
ml.Add(NewMatch("Fortuna Fürth", "Dynamo Dortmund", NewScore(2, 1)))
ml.Add(NewMatch("FC Frankfurt", "Concordia Cottbus", NewScore(1, 2)))

// Spieltag 3
ml.Add(NewMatch("Fortuna Fürth", "Concordia Cottbus", NewScore(2, 2)))
ml.Add(NewMatch("FC Frankfurt", "Dynamo Dortmund", NewScore(3, 2)))

fmt.Println(ml)
Output:

Fortuna Fürth - *FC Frankfurt*: 1:2
Dynamo Dortmund - Concordia Cottbus: 3:3
*Fortuna Fürth* - Dynamo Dortmund: 2:1
FC Frankfurt - *Concordia Cottbus*: 1:2
Fortuna Fürth - Concordia Cottbus: 2:2
*FC Frankfurt* - Dynamo Dortmund: 3:2

func (MatchList) Compare

func (ml MatchList) Compare(t1, t2 string) int

Compare erwartet zwei Teams und gibt zurück, ob das erste Team in der Tabelle vor dem zweiten Team steht. Falls t1 vor t2 steht, soll -1 zurückgegeben werden, falls t1 hinter t2 steht, soll 1 zurückgegeben werden. Falls t1 und t2 gleich stehen, soll 0 zurückgegeben werden. Die Teams sollen dabei nach den gleichen Regeln sortiert werden, wie in der Table-Methode.

Example
ml := NewMatchList(
	NewMatch("Fortuna Fürth", "FC Frankfurt", NewScore(1, 2)),
	NewMatch("Dynamo Dortmund", "Concordia Cottbus", NewScore(3, 3)),
	NewMatch("Fortuna Fürth", "Dynamo Dortmund", NewScore(2, 1)),
	NewMatch("FC Frankfurt", "Concordia Cottbus", NewScore(1, 2)),
	NewMatch("Fortuna Fürth", "Concordia Cottbus", NewScore(2, 2)),
	NewMatch("FC Frankfurt", "Dynamo Dortmund", NewScore(3, 2)),
)

fmt.Println(ml.Compare("Fortuna Fürth", "FC Frankfurt"))
fmt.Println(ml.Compare("FC Frankfurt", "Fortuna Fürth"))
fmt.Println(ml.Compare("FC Frankfurt", "FC Frankfurt"))
Output:

1
-1
0

func (MatchList) GoalDiff

func (ml MatchList) GoalDiff(name string) int

GoalDiff gibt die Tordifferenz der Mannschaft mit dem übergebenen Namen zurück.

Example
ml := NewMatchList(
	NewMatch("Fortuna Fürth", "FC Frankfurt", NewScore(1, 2)),
	NewMatch("Dynamo Dortmund", "Concordia Cottbus", NewScore(3, 3)),
	NewMatch("Fortuna Fürth", "Dynamo Dortmund", NewScore(2, 1)),
	NewMatch("FC Frankfurt", "Concordia Cottbus", NewScore(1, 2)),
	NewMatch("Fortuna Fürth", "Concordia Cottbus", NewScore(2, 2)),
	NewMatch("FC Frankfurt", "Dynamo Dortmund", NewScore(3, 2)),
)

fmt.Printf("Fortuna Fürth: %v\n", ml.GoalDiff("Fortuna Fürth"))
fmt.Printf("FC Frankfurt: %v\n", ml.GoalDiff("FC Frankfurt"))
fmt.Printf("Dynamo Dortmund: %v\n", ml.GoalDiff("Dynamo Dortmund"))
fmt.Printf("Concordia Cottbus: %v\n", ml.GoalDiff("Concordia Cottbus"))
Output:

Fortuna Fürth: 0
FC Frankfurt: 1
Dynamo Dortmund: -2
Concordia Cottbus: 1

func (MatchList) Points

func (ml MatchList) Points(name string) int

Points gibt die Punkte der Mannschaft mit dem übergebenen Namen zurück. Dabei gibt es für einen Sieg 3 Punkte, für ein Unentschieden 1 Punkt und für eine Niederlage 0 Punkte.

Example
ml := NewMatchList(
	NewMatch("Fortuna Fürth", "FC Frankfurt", NewScore(1, 2)),
	NewMatch("Dynamo Dortmund", "Concordia Cottbus", NewScore(3, 3)),
	NewMatch("Fortuna Fürth", "Dynamo Dortmund", NewScore(2, 1)),
	NewMatch("FC Frankfurt", "Concordia Cottbus", NewScore(1, 2)),
	NewMatch("Fortuna Fürth", "Concordia Cottbus", NewScore(2, 2)),
	NewMatch("FC Frankfurt", "Dynamo Dortmund", NewScore(3, 2)),
)

fmt.Printf("Fortuna Fürth: %v\n", ml.Points("Fortuna Fürth"))
fmt.Printf("FC Frankfurt: %v\n", ml.Points("FC Frankfurt"))
fmt.Printf("Dynamo Dortmund: %v\n", ml.Points("Dynamo Dortmund"))
fmt.Printf("Concordia Cottbus: %v\n", ml.Points("Concordia Cottbus"))
Output:

Fortuna Fürth: 4
FC Frankfurt: 6
Dynamo Dortmund: 1
Concordia Cottbus: 5

func (MatchList) String

func (ml MatchList) String() string

String gibt die MatchList als String zurück. Dabei sollen die einzelnen Matches jeweils in einer eigenen Zeile stehen. Für jedes Match soll die String-Methode des Match-Typs verwendet werden.

Example
ml := NewMatchList(
	NewMatch("Fortuna Fürth", "FC Frankfurt", NewScore(1, 2)),
	NewMatch("Dynamo Dortmund", "Concordia Cottbus", NewScore(3, 3)),
	NewMatch("Fortuna Fürth", "Dynamo Dortmund", NewScore(2, 1)),
	NewMatch("FC Frankfurt", "Concordia Cottbus", NewScore(1, 2)),
	NewMatch("Fortuna Fürth", "Concordia Cottbus", NewScore(2, 2)),
	NewMatch("FC Frankfurt", "Dynamo Dortmund", NewScore(3, 2)),
)

fmt.Println(ml)
Output:

Fortuna Fürth - *FC Frankfurt*: 1:2
Dynamo Dortmund - Concordia Cottbus: 3:3
*Fortuna Fürth* - Dynamo Dortmund: 2:1
FC Frankfurt - *Concordia Cottbus*: 1:2
Fortuna Fürth - Concordia Cottbus: 2:2
*FC Frankfurt* - Dynamo Dortmund: 3:2

func (MatchList) Table

func (ml MatchList) Table() []string

Table gibt die Tabelle der MatchList zurück. Dabei soll die Tabelle in jeder Zeile die Position, den Namen einer Mannschaft, die Anzahl der Punkte und die Tordifferenz enthalten. Die Mannschaften sollen dabei absteigend nach Punkten sortiert werden. Bei gleicher Punktzahl soll nach Tordifferenz sortiert werden. Bei gleicher Tordifferenz soll alphabetisch nach Namen sortiert werden.

Example
ml := NewMatchList(
	NewMatch("Fortuna Fürth", "FC Frankfurt", NewScore(1, 2)),
	NewMatch("Dynamo Dortmund", "Concordia Cottbus", NewScore(3, 3)),
	NewMatch("Fortuna Fürth", "Dynamo Dortmund", NewScore(2, 1)),
	NewMatch("FC Frankfurt", "Concordia Cottbus", NewScore(1, 2)),
	NewMatch("Fortuna Fürth", "Concordia Cottbus", NewScore(2, 2)),
	NewMatch("FC Frankfurt", "Dynamo Dortmund", NewScore(3, 2)),
)

table := ml.Table()
fmt.Println(strings.Join(table, "\n"))
Output:

1 FC Frankfurt 6 1
2 Concordia Cottbus 5 1
3 Fortuna Fürth 4 0
4 Dynamo Dortmund 1 -2

func (MatchList) Teams

func (ml MatchList) Teams() []string

Teams gibt die Namen aller Mannschaften zurück, die in der MatchList vorkommen. Dabei sollen die Namen alphabetisch sortiert sein. Jeder Name soll nur einmal vorkommen.

Example
ml := NewMatchList(
	NewMatch("Fortuna Fürth", "FC Frankfurt", NewScore(1, 2)),
	NewMatch("Dynamo Dortmund", "Concordia Cottbus", NewScore(3, 3)),
	NewMatch("Fortuna Fürth", "Dynamo Dortmund", NewScore(2, 1)),
	NewMatch("FC Frankfurt", "Concordia Cottbus", NewScore(1, 2)),
	NewMatch("Fortuna Fürth", "Concordia Cottbus", NewScore(2, 2)),
	NewMatch("FC Frankfurt", "Dynamo Dortmund", NewScore(3, 2)),
)

fmt.Println(ml.Teams())
Output:

[Concordia Cottbus Dynamo Dortmund FC Frankfurt Fortuna Fürth]

type Score

type Score struct {
	Home     int
	Visitors int
}

Score ist ein Datentyp, der einen Spielstand eines Spiels speichern soll. Gemeint ist etwas wie "1:0" oder "3:2".

Example
s := NewScore(1, 2)

fmt.Println(s)
Output:

1:2

func NewScore

func NewScore(home, visitors int) Score

NewScore erzeugt ein neues Score-Objekt mit den übergebenen Werten.

func (Score) Result

func (s Score) Result() int

Result gibt zurück, wer das Spiel gewonnen hat. 0: Unentschieden, 1: Heimmannschaft gewinnt, 2: Gäste gewinnen

Example
s1 := NewScore(1, 2)
s2 := NewScore(2, 1)
s3 := NewScore(2, 2)

fmt.Println(s1.Result())
fmt.Println(s2.Result())
fmt.Println(s3.Result())
Output:

2
1
0

func (Score) String

func (s Score) String() string

String gibt den Score als String in der Form "1:0" zurück.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL