mirror of
https://github.com/TheAlgorithms/Java.git
synced 2025-12-19 07:00:35 +08:00
refactor: improve code and test coverage for MapReduce example (#6348)
refactor: improve code and test coverage for MapReduce example
This commit is contained in:
committed by
GitHub
parent
350f149657
commit
4b6006c876
@@ -2,22 +2,14 @@ package com.thealgorithms.misc;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.params.ParameterizedTest;
|
||||
import org.junit.jupiter.params.provider.CsvSource;
|
||||
|
||||
public class MapReduceTest {
|
||||
@Test
|
||||
public void testMapReduceWithSingleWordSentence() {
|
||||
String oneWordSentence = "Hactober";
|
||||
String result = MapReduce.mapreduce(oneWordSentence);
|
||||
|
||||
assertEquals("Hactober: 1", result);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMapReduceWithMultipleWordSentence() {
|
||||
String multipleWordSentence = "I Love Love HactoberFest";
|
||||
String result = MapReduce.mapreduce(multipleWordSentence);
|
||||
|
||||
assertEquals("I: 1,Love: 2,HactoberFest: 1", result);
|
||||
@ParameterizedTest
|
||||
@CsvSource({"'hello world', 'hello: 1,world: 1'", "'one one two', 'one: 2,two: 1'", "'a a a a', 'a: 4'", "' spaced out ', 'spaced: 1,out: 1'"})
|
||||
void testCountWordFrequencies(String input, String expected) {
|
||||
String result = MapReduce.countWordFrequencies(input);
|
||||
assertEquals(expected, result);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user