public class TestLottery { static int BASE_RANDOM_NUM=1000; private static int getProbabilityIndex(final List<Double> probabilityList){ Map<Integer,Double> mapRates= calculateBaseProbability(probabilityList); int randomProbability=RandomUtils.nextInt(BASE_RANDOM_NUM); Set<Entry<Integer, Double>> sets=mapRates.entrySet(); for(Entry<Integer, Double> entry:sets){ if (entry.getValue() >= randomProbability && entry.getValue() <= BASE_RANDOM_NUM) { return entry.getKey(); } } return -1; } private static Map<Integer,Double> calculateBaseProbability(final List<Double> probabilityList){ Map<Integer,Double> mapRates=new HashMap<Integer, Double>(); double sumProbability=0.0; int index=0; Iterator<Double> itor= probabilityList.iterator(); while(itor.hasNext()){ double probability=itor.next(); if(probability>0){ sumProbability+=probability; mapRates.put(index, sumProbability*BASE_RANDOM_NUM); } index++; } return mapRates; } public static List<Double> createDoubleList(){ List<Double> orignalRates=new ArrayList<Double>(); orignalRates.add(0.0); orignalRates.add(0.0); orignalRates.add(0.6); orignalRates.add(0.3); orignalRates.add(0.1); return orignalRates; } public static void main(String[] args) { Map<Integer,Double> proMap=new HashMap<Integer, Double>(); double sumCount=100000; List<Double> orignalRates=createDoubleList(); for (double i = 0; i < sumCount; i++) { int index =getProbabilityIndex(orignalRates); if(proMap.containsKey(index)){ proMap.put(index, proMap.get(index)+1.0); }else{ proMap.put(index, 1.0); } } Set<Entry<Integer, Double>> setEntry=proMap.entrySet(); for(Entry<Integer, Double> entry:setEntry){ System.out.println( entry.getKey()+"("+entry.getValue()+")->rate:"+ entry.getValue()/sumCount); } } }
相关推荐
Instant Mock Testing with PowerMock 7 Saying Hello World! (Simple) 8 Getting and installing PowerMock (Simple) 14 Mocking static methods (Simple) 22 Verifying method invocation (Simple) 28 Mocking ...
tesunit junit easymock PowerMock
2020 Mock Exam B - Afternoon Session (with Solutions).pdf
Abstract Unit testing is a fundamental practice in Extreme Programming, but most ...“Once,” said the Mock Turtle at last, with a deep sigh, “I was a real Turtle.” (Alice In Wonderland, Lewis Carroll)
Classes contained in spring-mock.jar: org.springframework.mock.jndi.ExpectedLookupTemplate.class org.springframework.mock.jndi.SimpleNamingContext.class org.springframework.mock.jndi....
mock练习
2019年CFA一级mock打包
2020 Mock Exam A - Morning Session (with Solutions).pdf
简单的mockServer、模拟后台生成数据、启动后像后台一样直接调用接口
mock
CFA Mock
ApiMock操作文档
mock测试实战
Mock是一个零侵入的服务端Mock平台,底层基于JVM Sandbox。相比于Fiddler、-mock-fe
Django搭建mock系统
在java web应用中,进行用例实现时,很多情况难以模拟,比如数据库用例,如果直接通过连接数据库进行测试,导致用例对环境依赖很大,这时,可以通过mock技术可以模拟构造数据环境,从而进行单元测试,这里提供有实现...
实现JQuery+ajax+mock.js模拟注册,判断输入框是否输入正确
it is the cfa mock question, which is for 2013 June
基于webpac5 的devserver的mock数据配置
mock&mysql;问题