🚨 go fmt; go mod tidy

This commit is contained in:
Brian Wiborg 2024-05-13 10:45:38 +02:00
parent fb2a29be51
commit b0657a3fb2
No known key found for this signature in database
GPG key ID: BE53FA9286B719D6
20 changed files with 715 additions and 722 deletions

View file

@ -8,96 +8,96 @@ import (
type Quorum uint8
const (
Simple Quorum = iota
OneFifth
OneQuarter
OneThird
OneHalf
TwoFifths
TwoThirds
ThreeQuarters
ThreeFifths
FourFifths
Unanimous
Simple Quorum = iota
OneFifth
OneQuarter
OneThird
OneHalf
TwoFifths
TwoThirds
ThreeQuarters
ThreeFifths
FourFifths
Unanimous
)
func ValidQuorums() []Quorum {
return []Quorum{
Simple,
OneFifth, OneQuarter, OneThird, OneHalf,
TwoThirds, TwoFifths,
ThreeQuarters, ThreeFifths,
FourFifths,
}
return []Quorum{
Simple,
OneFifth, OneQuarter, OneThird, OneHalf,
TwoThirds, TwoFifths,
ThreeQuarters, ThreeFifths,
FourFifths,
}
}
func FromString(s string) (Quorum, error) {
for _, q := range ValidQuorums() {
if strings.ToUpper(q.String()) == strings.ToUpper(s) {
return q, nil
}
}
return Simple, fmt.Errorf("inalid quorum: %s", s)
for _, q := range ValidQuorums() {
if strings.ToUpper(q.String()) == strings.ToUpper(s) {
return q, nil
}
}
return Simple, fmt.Errorf("inalid quorum: %s", s)
}
func (q Quorum) String() string {
switch q {
case Simple:
return "SIMPLE"
case OneFifth:
return "1/5"
case OneQuarter:
return "1/4"
case OneThird:
return "1/3"
case OneHalf:
return "1/2"
case TwoThirds:
return "2/3"
case TwoFifths:
return "2/5"
case ThreeQuarters:
return "3/4"
case ThreeFifths:
return "3/5"
case FourFifths:
return "4/5"
case Unanimous:
return "ALL"
default:
panic("this code should never be reached")
}
switch q {
case Simple:
return "SIMPLE"
case OneFifth:
return "1/5"
case OneQuarter:
return "1/4"
case OneThird:
return "1/3"
case OneHalf:
return "1/2"
case TwoThirds:
return "2/3"
case TwoFifths:
return "2/5"
case ThreeQuarters:
return "3/4"
case ThreeFifths:
return "3/5"
case FourFifths:
return "4/5"
case Unanimous:
return "ALL"
default:
panic("this code should never be reached")
}
}
func (q Quorum) IsSatisfied(possibleVotes, totalVotes int) bool {
if totalVotes == 0 {
return false
}
switch q {
case Simple:
return true
case OneFifth:
return totalVotes * 5 >= possibleVotes
case OneQuarter:
return totalVotes * 4 >= possibleVotes
case OneThird:
return totalVotes * 3 >= possibleVotes
case OneHalf:
return totalVotes * 2 >= possibleVotes
case TwoThirds:
return totalVotes * 3 >= possibleVotes * 2
case TwoFifths:
return totalVotes * 5 >= possibleVotes * 2
case ThreeQuarters:
return totalVotes * 4 >= possibleVotes * 3
case ThreeFifths:
return totalVotes * 5 >= possibleVotes * 3
case FourFifths:
return totalVotes * 5 >= possibleVotes * 4
case Unanimous:
return totalVotes >= possibleVotes
default:
panic("this code should never be reached⚜")
}
return false
if totalVotes == 0 {
return false
}
switch q {
case Simple:
return true
case OneFifth:
return totalVotes*5 >= possibleVotes
case OneQuarter:
return totalVotes*4 >= possibleVotes
case OneThird:
return totalVotes*3 >= possibleVotes
case OneHalf:
return totalVotes*2 >= possibleVotes
case TwoThirds:
return totalVotes*3 >= possibleVotes*2
case TwoFifths:
return totalVotes*5 >= possibleVotes*2
case ThreeQuarters:
return totalVotes*4 >= possibleVotes*3
case ThreeFifths:
return totalVotes*5 >= possibleVotes*3
case FourFifths:
return totalVotes*5 >= possibleVotes*4
case Unanimous:
return totalVotes >= possibleVotes
default:
panic("this code should never be reached⚜")
}
return false
}