package ca.mokhan.test; import Q1.*; import junit.framework.Test; import junit.framework.TestCase; import junit.framework.TestSuite; public class ReversedSentenceTest extends TestCase { private ReversedSentence subject; public ReversedSentenceTest(String testName) { super(testName); this.subject = new ReversedSentence(); } public static Test suite() { return new TestSuite(ReversedSentenceTest.class); } public void testTruthy() { assertEquals(true, true); } public void testReverseByCharacter() { assertEquals( "bmal elttil a dah yram", ReversedSentence.reverseByCharacter("mary had a little lamb")); } public void testReverseByWord() { assertEquals( "lamb little a had mary", ReversedSentence.reverseByWord("mary had a little lamb")); } public void testChange5thPosition() { assertEquals( "mary zad azlittze lazb", ReversedSentence.change5thPosition("mary had a little lamb")); } public void testPrintChar2DArray() { char[][] matrix = new char[3][80]; String sentence = "mary had a little lamb"; matrix[0] = ReversedSentence.reverseByCharacter(sentence).toCharArray(); matrix[1] = ReversedSentence.reverseByWord(sentence).toCharArray(); matrix[2] = ReversedSentence.change5thPosition(sentence).toCharArray(); String expected = String.join( System.lineSeparator(), new String(matrix[0]), new String(matrix[1]), new String(matrix[2])); assertEquals(expected, ReversedSentence.printChar2DArray(matrix)); } public void testTruncateSentence() { String sentence = "mary had a little lamb"; assertEquals(sentence, ReversedSentence.truncateSentence(sentence)); String result = ReversedSentence.truncateSentence(createString(90, 'x')); assertEquals(80, result.length()); assertEquals(createString(80, 'x'), result); } private String createString(int length, char character) { StringBuffer buffer = new StringBuffer(length); for (int i = 0; i < length; i++) buffer.append(character); return buffer.toString(); } }