package com.matao.Q8;

import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;

import java.security.InvalidParameterException;

public class MinNumberInRotatedArrayTest {

    private MinNumberInRotatedArray minNumberInRotatedArray;

    @BeforeEach
    void setUp() {
        minNumberInRotatedArray = new MinNumberInRotatedArray();
    }

    @Test
    @DisplayName("test an increasing array before rotating")
    void testRotatedIncreasingArray() {
        int[] array = {3, 4, 5, 1, 2};
        Assertions.assertEquals(1, minNumberInRotatedArray.min(array));
    }

    @Test
    @DisplayName("test an array with repeated min number")
    void testRepeatedMinNumberArray() {
        int[] array = {3, 4, 5, 1, 1, 2};
        Assertions.assertEquals(1, minNumberInRotatedArray.min(array));
    }

    @Test
    @DisplayName("test an array with repeated number inside")
    void testRepeatedNumberInsideArray() {
        int[] array = {3, 4, 5, 1, 2, 2};
        Assertions.assertEquals(1, minNumberInRotatedArray.min(array));
    }

    @Test
    @DisplayName("test an array with repeated number in head and tail")
    void testRepeatedNumberInHeadTailArray() {
        int[] array = {1, 0, 1, 1, 1};
        Assertions.assertEquals(0, minNumberInRotatedArray.min(array));
    }

    @Test
    @DisplayName("test an increasing array")
    void testIncreasingArray() {
        int[] array = {1, 2, 3, 4, 5};
        Assertions.assertEquals(1, minNumberInRotatedArray.min(array));
    }

    @Test
    @DisplayName("test single number array")
    void testSingleNumberArray() {
        int[] array = {2};
        Assertions.assertEquals(2, minNumberInRotatedArray.min(array));
    }

    @Test
    @DisplayName("test null array")
    void testNullArray() {
        int[] array = null;
        Assertions.assertThrows(InvalidParameterException.class, () -> minNumberInRotatedArray.min(array));
    }
}

@@ -14,13 +14,61 @@
 atao
-.Q8;%0A
+;%0A%0Aimport com.matao.common.InvalidParameterException;
 %0Aimp
@@ -228,57 +228,8 @@
 t;%0A%0A
-import java.security.InvalidParameterException;%0A%0A
 publ
@@ -237,16 +237,20 @@
 c class 
+Q11_
 MinNumbe
@@ -284,16 +284,20 @@
 private 
+Q11_
 MinNumbe
@@ -411,16 +411,20 @@
 y = new 
+Q11_
 MinNumbe
@@ -1870,36 +1870,8 @@
 ) %7B%0A
-        int%5B%5D array = null;%0A
     
@@ -1957,33 +1957,32 @@
 otatedArray.min(
-array
+null
 ));%0A    %7D%0A%7D%0A

add test cases for MinNumberInRotatedArray