package com.walker.etaa; import com.walker.etaa.util.AlgorithmUtils; import java.util.List; import java.util.Random; public class TestExtract { // @Test public void testRandomAlgorithm(){ for(int j=0; j<10; j++){ int[] result = AlgorithmUtils.getRandomIndexArray(100, j+5); if(result != null){ for(int i : result){ System.out.print(i); System.out.print(","); } System.out.println("-----------------"); } } } // @Test public void testExtractAverageItem() throws ExtractFailedException{ DemoSimpleExtractor extractor = new DemoSimpleExtractor(); QuestionExtractOptions options = new QuestionExtractOptions(); options.setGlobalConfig("default", "", "历史", 2); // options.addOption("国际历史", null, QuestionType.TrueOrFalse, null, 2); // options.addOption("国际历史", null, QuestionType.SelectMultiple, null, 2); options.addOption("国际历史", null, null, 2); List list = (List)extractor.extract(options); } // @Test public void testExtractAverage() throws ExtractFailedException{ DemoSimpleExtractor extractor = new DemoSimpleExtractor(); QuestionExtractOptions options = new QuestionExtractOptions(); options.setGlobalConfig("default", "", "数学", 10); options.setExtractStrategy(ExtractStrategy.Average); // 设置凑齐策略:默认随机 List list = (List)extractor.extract(options); } // @Test public void testAverageIndex(){ int existTotal = 200; int requiredTotal = 32; int span = existTotal / requiredTotal; Random random = new Random(); int offset = random.nextInt(10); System.out.println("offset = " + offset); if(span == 1){ for(int i=0; i 1){ int current = offset; if(current == 0){ current = 1; } int last = AlgorithmUtils.getAverageLastIndex(current, span, requiredTotal); while(last > existTotal){ System.out.println("最后元素超过了'existTotal',last = " + last); if(span > 1){ span --; } else if(offset > 1){ offset --; } else { System.out.println("已经无法降低抽取间隔了,退出循环"); break; } last = AlgorithmUtils.getAverageLastIndex(current, span, requiredTotal); } for(int i=0; i 0){ current += span; } System.out.println("get " + (current)); } return; } } }