DataGenerator { public Collection<AssignedLabel<String>> generateLabels(Collection<ArtificialWorker> workers, TroiaObjectCollection objects, int workersPerObject) { Collection<AssignedLabel<String>> labels = new ArrayList<AssignedLabel<String>>(); Map<ArtificialWorker, NoisedLabelGenerator> generators = NoisedLabelGeneratorFactory .getInstance().getRouletteGeneratorsForWorkers(workers); Iterator<ArtificialWorker> workersIterator = workers.iterator(); for (String object : objects) { String correctCat = objects.getCategory(object); ArtificialWorker worker; for (int labelsForObject = 0; labelsForObject < workersPerObject; labelsForObject++) { String assignedLabel; if (!workersIterator.hasNext()) { workersIterator = workers.iterator(); } worker = workersIterator.next(); assignedLabel = generators.get(worker).getCategoryWithNoise( correctCat); labels.add(new AssignedLabel<String>(worker, new LObject<String>(object), assignedLabel)); } } return labels; } private  DataGenerator(); TroiaObjectCollection generateTestObjects(int objectCount,
			Map<String, Double> categories); TroiaObjectCollection generateTestObjects(int objectCount,
			int categoryCount); TroiaObjectCollection generateTestObjects(int objectCount,
			Collection<String> categoryNames); Collection<String> generateCategoryNames(int categoryCount); ArtificialWorker generateArtificialWorker(String name,
			double quality, Collection<String> categories); ArtificialWorker generateArtificialWorker(String name,
			Collection<String> categories); Collection<ArtificialWorker> generateArtificialWorkers(
		int workerCount, Collection<String> categories, double minQuality,
		double maxQuality); Collection<AssignedLabel<String>> generateLabels(Collection<ArtificialWorker> workers, TroiaObjectCollection objects, int workersPerObject); Collection<LObject<String>> generateGoldLabels(
		TroiaObjectCollection objects, double goldCoverage); Collection<Map<String, Object>> computeArtificialWorkerQualities(
			Collection<String> categories,
			TroiaObjectCollection objects,
			Collection<ArtificialWorker> workers,
			Collection<AssignedLabel<String>> labels,
			Collection<LObject<String>> goldLabels); Data generateTestData(String requestId, int objectCount,
			int categoryCount, int workerCount, double minQuality,
			double maxQuality, double goldRatio, int workersPerObject); static DataGenerator getInstance(); final static double CONFUSION_VECTOR_SUM_EPSILON; }
@Test public void testGenerateLabels() { final int categoriesCount = 5; final int objectsCount = 100000; final int workersCount = 1000; final double minQuality = 0; final double maxQuality = 1; final int workersPerObject = 1; DataGenerator generator = DataGenerator.getInstance(); Collection<String> categories = generator.generateCategoryNames(categoriesCount); TroiaObjectCollection objects = generator.generateTestObjects(objectsCount, categories); Collection<ArtificialWorker> workers = generator.generateArtificialWorkers( workersCount, categories, minQuality, maxQuality); Collection<AssignedLabel<String>> labels = generator.generateLabels(workers, objects, workersPerObject); int correct = 0; int total = 0; for (AssignedLabel<String> label : labels) { if (label.getLabel().equals( objects.getCategory(label.getLobject().getName()))) { correct++; } total++; } double percentage = (double)correct / (double)total; assertEquals(percentage, 0.5, 0.1); }