Repository: TheAlgorithms/Java
File: src/test/java/com/thealgorithms/misc/MedianOfRunningArrayTest.java (Java)

Code before:
        stream.insert(1);
        assertEquals(17.5, stream.median());
    }

    @Test
    public void testWithNegativeAndPositiveValues() {
        MedianOfRunningArray stream = new MedianOfRunningArray();
        stream.insert(-1);
        assertEquals(-1, stream.median());
        stream.insert(2);
        assertEquals(0.5, stream.median());
        stream.insert(-3);
        assertEquals(-1, stream.median());
    }

    @Test
    public void testWithDuplicateValues() {
        MedianOfRunningArray stream = new MedianOfRunningArray();
        stream.insert(-1);
        assertEquals(-1, stream.median());
        stream.insert(-1);
        assertEquals(-1, stream.median());
        stream.insert(-1);
        assertEquals(-1, stream.median());
    }

    @Test
    public void testWithLargeValues() {
        MedianOfRunningArray stream = new MedianOfRunningArray();
        stream.insert(1000000);
        assertEquals(1000000, stream.median());
        stream.insert(12000);
        assertEquals(506000, stream.median());
        stream.insert(15000000);
        assertEquals(1000000, stream.median());
        stream.insert(2300000);
        assertEquals(1650000.00, stream.median());
    }

    @Test
    public void testWithLargeCountOfValues() {
        MedianOfRunningArray stream = new MedianOfRunningArray();
        for (int i = 1; i <= 1000; i++) stream.insert(i);
        assertEquals(500.5, stream.median());
    }
}


Review comment (refactor):
```suggestion

    @Test
    public void testWithDuplicateValuesB() {
        MedianOfRunningArray stream = new MedianOfRunningArray();
        stream.insert(10);
        stream.insert(20);
        stream.insert(10);
        stream.insert(10);
        stream.insert(20);
        stream.insert(0);
        stream.insert(50);
        assertEquals(10, stream.median());
    }

```

Code after:
        stream.insert(1);
        assertEquals(17.5, stream.median());
    }

    @Test
    public void testWithNegativeAndPositiveValues() {
        MedianOfRunningArray stream = new MedianOfRunningArray();
        stream.insert(-1);
        assertEquals(-1, stream.median());
        stream.insert(2);
        assertEquals(0.5, stream.median());
        stream.insert(-3);
        assertEquals(-1, stream.median());
    }

    @Test
    public void testWithDuplicateValues() {
        MedianOfRunningArray stream = new MedianOfRunningArray();
        stream.insert(-1);
        assertEquals(-1, stream.median());
        stream.insert(-1);
        assertEquals(-1, stream.median());
        stream.insert(-1);
        assertEquals(-1, stream.median());
    }

    @Test
    public void testWithDuplicateValuesB() {
        MedianOfRunningArray stream = new MedianOfRunningArray();
        stream.insert(10);
        stream.insert(20);
        stream.insert(10);
        stream.insert(10);
        stream.insert(20);
        stream.insert(0);
        stream.insert(50);
        assertEquals(10, stream.median());
    }

    @Test
    public void testWithLargeValues() {
        MedianOfRunningArray stream = new MedianOfRunningArray();
        stream.insert(1000000);
        assertEquals(1000000, stream.median());
        stream.insert(12000);
        assertEquals(506000, stream.median());
        stream.insert(15000000);
        assertEquals(1000000, stream.median());
        stream.insert(2300000);
        assertEquals(1650000.00, stream.median());
    }