package net.ranides.assira.generic;

import org.junit.Test;

import net.ranides.assira.text.NaturalComparator;

import java.util.Arrays;

import static org.junit.Assert.assertArrayEquals;

public class NaturalComparatorTest {

    @Test
    public void simple() {
        String[] list = {"hello3", "hello20", "hello1"};
        Arrays.sort(list, NaturalComparator.comparator());
        assertArrayEquals(new String[]{"hello1", "hello3", "hello20"}, list);
    }

    @Test
    public void separators() {
        String[] list = {"hello3.14", "hello4.0", "hello3.0.1"};
        Arrays.sort(list, NaturalComparator.comparator());
//        System.out.println(Arrays.toString(list));
        assertArrayEquals(new String[]{"hello3.0.1", "hello3.14", "hello4.0"}, list);
    }

    @Test
    public void separators2() {
        String[] list = {"hello3.14", "hello4.0", "hello3.7.1", "hello3.20.1", "hello3.2.1"};
        Arrays.sort(list, NaturalComparator.comparator());
        assertArrayEquals(new String[]{"hello3.2.1", "hello3.7.1", "hello3.14", "hello3.20.1", "hello4.0"}, list);
    }
}