List of usage examples for org.apache.commons.math3.fraction BigFraction BigFraction
public BigFraction(final long num, final long den)
Create a BigFraction given the numerator and denominator as simple long.
From source file:info.gehrels.voting.NotMoreThanTheAllowedNumberOfCandidatesCanReachItQuorum.java
@Override public final BigFraction calculateQuorum(long numberOfValidVotes, long numberOfSeats) { BigFraction calculatedQuorum = new BigFraction(numberOfValidVotes, (numberOfSeats + 1)).add(surplus); return correctToBoundariesIfNecessary(numberOfValidVotes, numberOfSeats, calculatedQuorum); }
From source file:info.gehrels.voting.NotMoreThanTheAllowedNumberOfCandidatesCanReachItQuorumTest.java
@Test public void returnsCorrectQuorumForNonZeroNumberOfValidVotesAndZeroPositions() { QuorumCalculation defaultQuorumCalculation = new NotMoreThanTheAllowedNumberOfCandidatesCanReachItQuorum( ONE_TENTH);// w w w. j ava 2 s .c o m BigFraction quorum = defaultQuorumCalculation.calculateQuorum(4, 0); assertThat(quorum, is(new BigFraction(41, 10))); }
From source file:co.turnus.util.ProgressTheadPrinter.java
public void run() { SimpleTimer globalTimer = new SimpleTimer(); SimpleTimer stepTimer = new SimpleTimer(); final long stepsReduced = steps / 100; do {/*w ww. j ava 2s . c om*/ int val = stepsReduced != 0 ? new BigFraction(step, stepsReduced).intValue() : 0; if (val != currentValue) { currentValue = val; // if (val % 10 == 0) { TurnusLogger.info(message + val + "% after " + stepTimer.getElapsedTime() / 1000 + "s"); stepTimer.reset(); // } } try { Thread.sleep(sleepTime); } catch (Exception e) { } } while (run && step < steps); TurnusLogger.info(new StringBuilder().append(message).append("done in ") .append((int) (globalTimer.getElapsedTime() / 1000)).append("s").toString()); }
From source file:info.gehrels.voting.NotMoreThanTheAllowedNumberOfCandidatesCanReachItQuorumTest.java
@Test public void returnsCorrectQuorumForNonZeroNumberOfValidVotesAndNonZeroNumberOfPositions() { QuorumCalculation defaultQuorumCalculation = new NotMoreThanTheAllowedNumberOfCandidatesCanReachItQuorum( ONE_TENTH);/*from www. ja v a 2 s .c o m*/ BigFraction quorum = defaultQuorumCalculation.calculateQuorum(6, 2); assertThat(quorum, is(new BigFraction(21, 10))); }
From source file:com.netflix.imfutility.ConversionHelperTest.java
@Test public void toEditRate() { assertEquals("30000 1001", ConversionHelper.toEditRate(new BigFraction(30000, 1001))); assertEquals("50 1", ConversionHelper.toEditRate(new BigFraction(50))); }
From source file:info.gehrels.voting.singleTransferableVote.WeightedInclusiveGregoryMethodTest.java
@Test public void reducesVoteWeightOfThoseBallotsThatHadTheElectedCandidateAsCurrentPreferredCandidate() { VoteWeightRecalculator<Candidate> voteWeightRecalculator = wigm.recalculatorFor(); ImmutableCollection<VoteState<Candidate>> voteStates = voteWeightRecalculator.recalculateExceededVoteWeight( CANDIDATE_A, new BigFraction(7, 8), VOTE_STATES_FIXTURE, ALL_HOPEFUL_CANDIDATE_STATE); assertThat(voteStates,/* www . j a va2 s . com*/ hasItems( aVoteState(Matchers.<VoteState<Candidate>>allOf(withVoteWeight(ONE_HALF), withBallotId(BALLOT_ABCD.id))), aVoteState(Matchers.<VoteState<Candidate>>allOf(withBallotId(BALLOT_ACD.id), withVoteWeight(new BigFraction(3, 8)))))); }
From source file:com.netflix.imfutility.ConversionHelperTest.java
@Test public void toREditRate() { assertEquals("30000/1001", ConversionHelper.toREditRate(new BigFraction(30000, 1001))); assertEquals("50/1", ConversionHelper.toREditRate(new BigFraction(50))); }
From source file:com.netflix.imfutility.ConversionHelperTest.java
@Test public void parseCorrectEditRate() { assertEquals(new BigFraction(30000, 1001), ConversionHelper.parseEditRate("30000 1001")); assertEquals(new BigFraction(50, 1), ConversionHelper.parseEditRate("50")); assertEquals(new BigFraction(30000, 1001), ConversionHelper.parseEditRate("30000/1001")); assertEquals(new BigFraction(50, 1), ConversionHelper.parseEditRate("50 1")); }
From source file:info.gehrels.voting.singleTransferableVote.WeightedInclusiveGregoryMethodTest.java
@Test public void reportsEachVoteWeightRedistribution() { VoteWeightRecalculator<Candidate> voteWeightRecalculator = wigm.recalculatorFor(); voteWeightRecalculator.recalculateExceededVoteWeight(CANDIDATE_A, new BigFraction(7, 8), VOTE_STATES_FIXTURE, ALL_HOPEFUL_CANDIDATE_STATE); verify(listenerMock).redistributingExcessiveFractionOfVoteWeight(CANDIDATE_A, ONE_HALF); }
From source file:cc.redberry.core.number.Rational.java
/** * @see BigFraction#BigFraction(java.math.BigInteger, java.math.BigInteger) *//*from w w w . ja va 2s .co m*/ public Rational(BigInteger num, BigInteger den) { checkNotNull(num); checkNotNull(den); fraction = new BigFraction(num, den); }