{"version":3,"sources":["../../src/actors/vote.ts"],"sourcesContent":["/**\n * The results of a binary vote.\n * The blank votes are not counted. To calculate a threshold on the whole\n * number of members, use vote.votesFor / house.nSeats.\n * To calculate the threshold on the number of duly elected members, use\n * vote.votesFor / sum(house.members.values()).\n */\nexport class Vote {\n    constructor(\n        public readonly votesFor: number,\n        public readonly votesAgainst: number,\n    ) { }\n\n    /**\n     * Returns the reverse of the vote, inverting the for/against ratio.\n     * Simulates a vote on the opposite motion.\n     */\n    get neg(): Vote {\n        return new Vote(this.votesAgainst, this.votesFor);\n    }\n\n    get votesCast(): number {\n        return this.votesFor + this.votesAgainst;\n    }\n\n    /**\n     * Returns the ratio of votes for over the total number of votes cast.\n     * If there are no votes cast, returns an Infinity.\n     */\n    get ratio(): number {\n        return this.votesFor / this.votesCast;\n    }\n\n    /**\n     * Returns the votes in order of decreasing ratio.\n     * The ties are ordered by decreasing number of positive votes,\n     * and then by the order they came in.\n     */\n    static order(votes: Vote[]): Vote[] {\n        return votes\n            .sort((a, b) => (b.ratio - a.ratio) || (b.votesFor - a.votesFor));\n    }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAOO,IAAM,OAAN,MAAM,MAAK;AAAA,EACd,YACoB,UACA,cAClB;AAFkB;AACA;AAAA,EAChB;AAAA;AAAA;AAAA;AAAA;AAAA,EAMJ,IAAI,MAAY;AACZ,WAAO,IAAI,MAAK,KAAK,cAAc,KAAK,QAAQ;AAAA,EACpD;AAAA,EAEA,IAAI,YAAoB;AACpB,WAAO,KAAK,WAAW,KAAK;AAAA,EAChC;AAAA;AAAA;AAAA;AAAA;AAAA,EAMA,IAAI,QAAgB;AAChB,WAAO,KAAK,WAAW,KAAK;AAAA,EAChC;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAOA,OAAO,MAAM,OAAuB;AAChC,WAAO,MACF,KAAK,CAAC,GAAG,MAAO,EAAE,QAAQ,EAAE,SAAW,EAAE,WAAW,EAAE,QAAS;AAAA,EACxE;AACJ;","names":[]}