<commit_before>import junit.framework.TestCase;

/**
 * Test Program 3: Dynamic Programming
 * EID: js68634
 * Created by <NAME> on 8/3/16.
 */
public class Program3Test extends TestCase {
	private int sum(int[] integers) {
		int total = 0;
		for(int i : integers) total += i;
		return total;
	}

	public void testInitialize() throws Exception {
		Program3 program = new Program3();
		int numClasses = 10, maxGrade = 3;
		GradeFunction gradeFunction = new SquareRootGradeFunction(numClasses, maxGrade);
		program.initialize(numClasses, maxGrade, gradeFunction);
		assertEquals(numClasses, program.getNumClasses());
		assertEquals(maxGrade, program.getMaxGrade());
		assertSame(gradeFunction, program.getGradeFunction());
	}

	public void testComputeHoursSquareRoot() throws Exception {
		Program3 program = new Program3();
		int n = 10;
		int H = 40;
		int maxGrade = 3;
		program.initialize(n, maxGrade, new SquareRootGradeFunction(n, maxGrade));

		assertEquals(H, sum(program.computeHours(H)));
	}

	public void testComputeGradesSquareRoot() throws Exception {
		Program3 program = new Program3();
		int n = 10;
		int H = 40;
		int maxGrade = 3;
		program.initialize(n, maxGrade, new SquareRootGradeFunction(n, maxGrade));
		assertEquals(22, sum(program.computeGrades(H)));
	}

	public void testComputeGradesCustom() throws Exception {
		Program3 program = new Program3();
		int n = 10;
		int H = 20;
		int maxGrade = 10;
		program.initialize(n, maxGrade, new CustomGradeFunction(n, maxGrade));

		assertEquals(35, sum(program.computeGrades(H)));
	}

	public void testMyGradeFunction() throws Exception {
		Program3 program = new Program3();
		int n = 10;
		int H = 40;
		int maxGrade = 10;
		program.initialize(n, maxGrade, new MyGradeFunction(n, maxGrade));
		assertEquals(H, sum(program.computeHours(H)));
		assertEquals(49, sum(program.computeGrades(H)));
	}

	/** Test successive calls to Program3 don't corrupt the state of the instance */
	public void testSuccessiveRunsOnProgram() throws Exception {
		Program3 program = new Program3();
		int n = 10;
		int H = 40;
		int maxGrade = 10;
		program.initialize(n, maxGrade, new SquareRootGradeFunction(n, maxGrade));
		assertEquals(H, sum(program.computeHours(H)));
		assertEquals(22, sum(program.computeGrades(H)));

		H = 20;
		assertEquals(15, sum(program.computeGrades(H)));

		H = 80;
		assertEquals(31, sum(program.computeGrades(H)));
	}

	/** Test case where no work can be done to improve the overall grade */
	public void testAllZeros() throws Exception {
		Program3 program = new Program3();
		int n = 10;
		int H = 40;
		int maxGrade = 10;
		program.initialize(n, maxGrade, new GradeFunction() {
			@Override
			public int grade(int classID, int hours) {
				return 0;
			}
		});
		assertEquals(0, sum(program.computeHours(H)));
		assertEquals(0, sum(program.computeGrades(H)));
	}

	/** Test another custom grade function for completeness sake. */
	public void testIncreaseOnClassId() throws Exception {
		Program3 program = new Program3();
		final int n = 10;
		int H = 40;
		final int maxGrade = 10;
		program.initialize(n, maxGrade, new GradeFunction() {
			@Override
			public int grade(int classID, int hours) {
				if(hours == n - classID) return Math.min(maxGrade, classID);
				return 0;
			}
		});
		assertEquals(40, sum(program.computeHours(H)));
		assertEquals(44, sum(program.computeGrades(H)));
	}

	/** Ensure that if every class is an easy-A then no work is done at all. */
	public void testAllMax() throws Exception {
		Program3 program = new Program3();
		int n = 10;
		int H = 40;
		final int maxGrade = 10;
		program.initialize(n, maxGrade, new GradeFunction() {
			@Override
			public int grade(int classID, int hours) {
				return maxGrade;
			}
		});
		assertEquals(0, sum(program.computeHours(H)));
		assertEquals(100, sum(program.computeGrades(H)));
	}
}<commit_msg>Lab3: Add double initialize test<commit_after>import junit.framework.TestCase;

/**
 * Test Program 3: Dynamic Programming
 * EID: js68634
 * Created by <NAME> on 8/3/16.
 */
public class Program3Test extends TestCase {
	private int sum(int[] integers) {
		int total = 0;
		for(int i : integers) total += i;
		return total;
	}

	public void testInitialize() throws Exception {
		Program3 program = new Program3();
		int numClasses = 10, maxGrade = 3;
		GradeFunction gradeFunction = new SquareRootGradeFunction(numClasses, maxGrade);
		program.initialize(numClasses, maxGrade, gradeFunction);
		assertEquals(numClasses, program.getNumClasses());
		assertEquals(maxGrade, program.getMaxGrade());
		assertSame(gradeFunction, program.getGradeFunction());
	}

	public void testComputeHoursSquareRoot() throws Exception {
		Program3 program = new Program3();
		int n = 10;
		int H = 40;
		int maxGrade = 3;
		program.initialize(n, maxGrade, new SquareRootGradeFunction(n, maxGrade));

		assertEquals(H, sum(program.computeHours(H)));
	}

	public void testComputeGradesSquareRoot() throws Exception {
		Program3 program = new Program3();
		int n = 10;
		int H = 40;
		int maxGrade = 3;
		program.initialize(n, maxGrade, new SquareRootGradeFunction(n, maxGrade));
		assertEquals(22, sum(program.computeGrades(H)));
	}

	public void testComputeGradesCustom() throws Exception {
		Program3 program = new Program3();
		int n = 10;
		int H = 20;
		int maxGrade = 10;
		program.initialize(n, maxGrade, new CustomGradeFunction(n, maxGrade));

		assertEquals(35, sum(program.computeGrades(H)));
	}

	public void testMyGradeFunction() throws Exception {
		Program3 program = new Program3();
		int n = 10;
		int H = 40;
		int maxGrade = 10;
		program.initialize(n, maxGrade, new MyGradeFunction(n, maxGrade));
		assertEquals(H, sum(program.computeHours(H)));
		assertEquals(49, sum(program.computeGrades(H)));
	}

	/** Test successive calls to Program3 don't corrupt the state of the instance */
	public void testSuccessiveRunsOnProgram() throws Exception {
		Program3 program = new Program3();
		int n = 10;
		int H = 40;
		int maxGrade = 10;
		program.initialize(n, maxGrade, new SquareRootGradeFunction(n, maxGrade));
		assertEquals(H, sum(program.computeHours(H)));
		assertEquals(22, sum(program.computeGrades(H)));

		H = 20;
		assertEquals(15, sum(program.computeGrades(H)));

		H = 80;
		assertEquals(31, sum(program.computeGrades(H)));

		n = 20;
		H = 40;
		maxGrade = 10;
		program.initialize(n, maxGrade, new SquareRootGradeFunction(n, maxGrade));
		assertEquals(H, sum(program.computeHours(H)));
		assertEquals(30, sum(program.computeGrades(H)));

		H = 20;
		assertEquals(20, sum(program.computeGrades(H)));

		H = 80;
		assertEquals(45, sum(program.computeGrades(H)));
	}

	/** Test case where no work can be done to improve the overall grade */
	public void testAllZeros() throws Exception {
		Program3 program = new Program3();
		int n = 10;
		int H = 40;
		int maxGrade = 10;
		program.initialize(n, maxGrade, new GradeFunction() {
			@Override
			public int grade(int classID, int hours) {
				return 0;
			}
		});
		assertEquals(0, sum(program.computeHours(H)));
		assertEquals(0, sum(program.computeGrades(H)));
	}

	/** Test another custom grade function for completeness sake. */
	public void testIncreaseOnClassId() throws Exception {
		Program3 program = new Program3();
		final int n = 10;
		int H = 40;
		final int maxGrade = 10;
		program.initialize(n, maxGrade, new GradeFunction() {
			@Override
			public int grade(int classID, int hours) {
				if(hours == n - classID) return Math.min(maxGrade, classID);
				return 0;
			}
		});
		assertEquals(40, sum(program.computeHours(H)));
		assertEquals(44, sum(program.computeGrades(H)));
	}

	/** Ensure that if every class is an easy-A then no work is done at all. */
	public void testAllMax() throws Exception {
		Program3 program = new Program3();
		int n = 10;
		int H = 40;
		final int maxGrade = 10;
		program.initialize(n, maxGrade, new GradeFunction() {
			@Override
			public int grade(int classID, int hours) {
				return maxGrade;
			}
		});
		assertEquals(0, sum(program.computeHours(H)));
		assertEquals(100, sum(program.computeGrades(H)));
	}
}
{'fraction_non_alphanumeric': 0.12159484893511639, 'fraction_numerical': 0.028850916295195643, 'mean_word_length': 4.373918829008649, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2215554', 'n_tokens_mistral': 2997, 'n_tokens_neox': 2512, 'n_words': 747}