protocol

package
v0.0.0-...-02afb0d Latest Latest
Warning

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

Go to latest
Published: Sep 22, 2020 License: BSD-3-Clause Imports: 2 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ProtocolCommandMap = map[string]Protocol{
	"simpleMajority": new(SimpleMajority),
}

Consumed by cmd/serve.go

Functions

This section is empty.

Types

type Candidate

type Candidate struct {
	Name string
}

type Election

type Election struct {
	Id         string
	Name       string
	Candidates []Candidate
	Votes      []Vote
	Totals     map[string]float64 // Candidate name to their total
}

type Protocol

type Protocol interface {
	Init([]Candidate)
	Cast(Vote)                   // Cast a vote
	Tally()                      // Compute the candidate's totals
	Result() ([]string, float64) // Get the final result(s)
	Display()                    // Print the current totals
	GetId() string               // Get the id of the election
	ValidateVote(Vote) bool      // Return if a cast vote is valid
}

type SimpleMajority

type SimpleMajority struct {
	Election
}

func (*SimpleMajority) Cast

func (election *SimpleMajority) Cast(vote Vote)

func (*SimpleMajority) Display

func (election *SimpleMajority) Display()

func (*SimpleMajority) GetId

func (election *SimpleMajority) GetId() string

func (*SimpleMajority) Init

func (election *SimpleMajority) Init(candidates []Candidate)

func (*SimpleMajority) Result

func (election *SimpleMajority) Result() ([]string, float64)

func (*SimpleMajority) Tally

func (election *SimpleMajority) Tally()

func (*SimpleMajority) ValidateVote

func (election *SimpleMajority) ValidateVote(vote Vote) bool

type Vote

type Vote struct {
	Value     float64
	Candidate Candidate
}

Jump to

Keyboard shortcuts

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