@Test public void fullSum() throws Exception { int wantedSum = Quantiser.QuantiserProcesses.PRICE_APPLICABLE_PERM.getCost() + Quantiser.QuantiserProcesses.PRICE_CHECK_2048_SIG.getCost() + Quantiser.QuantiserProcesses.PRICE_CHECK_4096_SIG.getCost() + Quantiser.QuantiserProcesses.PRICE_CHECK_REFERENCED_VERSION.getCost() + Quantiser.QuantiserProcesses.PRICE_REGISTER_VERSION.getCost() + Quantiser.QuantiserProcesses.PRICE_REVOKE_VERSION.getCost() + Quantiser.QuantiserProcesses.PRICE_SPLITJOIN_PERM.getCost(); try { byte[] hashBytes = new byte[128]; new Random().nextBytes(hashBytes); HashId hashId = new HashId(hashBytes); Quantiser q = new Quantiser(); q.reset(wantedSum); q.addWorkCost(Quantiser.QuantiserProcesses.PRICE_APPLICABLE_PERM); q.addWorkCost(Quantiser.QuantiserProcesses.PRICE_CHECK_2048_SIG); q.addWorkCost(Quantiser.QuantiserProcesses.PRICE_CHECK_4096_SIG); q.addWorkCost(Quantiser.QuantiserProcesses.PRICE_CHECK_REFERENCED_VERSION); q.addWorkCost(Quantiser.QuantiserProcesses.PRICE_REGISTER_VERSION); q.addWorkCost(Quantiser.QuantiserProcesses.PRICE_REVOKE_VERSION); q.addWorkCost(Quantiser.QuantiserProcesses.PRICE_SPLITJOIN_PERM); assertEquals(wantedSum, q.getQuantaSum()); } catch (Quantiser.QuantiserException e) { fail(); } }
public void addWorkCost(QuantiserProcesses process) throws QuantiserException { quantaSum_ += process.getCost(); // System.out.println("Add processing cost for " + process + " (" + process.getCost() + "), now cost is " + quantaSum_ + ", limit is " + quantaLimit_); if (quantaLimit_ >= 0) if (quantaSum_ > quantaLimit_){ // System.out.println("Limit, break "); throw new QuantiserException(); } }