<commit_before>package name.abuchen.portfolio.util;

import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.MatcherAssert.assertThat;

import java.time.LocalDate;
import java.util.concurrent.ThreadLocalRandom;

import org.junit.Test;

@SuppressWarnings("nls")
public class TradeCalendarTest
{

    @Test
    public void testEasterHolidays()
    {
        TradeCalendar calendar = TradeCalendarManager.getInstance("de");

        assertThat(calendar.isHoliday(LocalDate.parse("2015-04-02")), is(false));
        assertThat(calendar.isHoliday(LocalDate.parse("2015-04-03")), is(true));
        assertThat(calendar.isHoliday(LocalDate.parse("2015-04-04")), is(true));
        assertThat(calendar.isHoliday(LocalDate.parse("2015-04-05")), is(true));
        assertThat(calendar.isHoliday(LocalDate.parse("2015-04-06")), is(true));
        assertThat(calendar.isHoliday(LocalDate.parse("2015-04-07")), is(false));

        assertThat(calendar.isHoliday(LocalDate.parse("2016-03-25")), is(true));
    }

    @Test
    public void testWeekends()
    {
        TradeCalendar calendar = TradeCalendarManager.getInstance("de");

        assertThat(calendar.isHoliday(LocalDate.parse("2015-01-31")), is(true));
        assertThat(calendar.isHoliday(LocalDate.parse("2015-02-01")), is(true));
    }

    @Test
    public void testFixedPublicHolidays()
    {
        TradeCalendar calendar = TradeCalendarManager.getInstance("de");

        assertThat(calendar.isHoliday(LocalDate.parse("2015-01-01")), is(true));
        assertThat(calendar.isHoliday(LocalDate.parse("2015-05-01")), is(true));
        assertThat(calendar.isHoliday(LocalDate.parse("2015-12-24")), is(true));
        assertThat(calendar.isHoliday(LocalDate.parse("2015-12-25")), is(true));
        assertThat(calendar.isHoliday(LocalDate.parse("2015-12-26")), is(true));

        assertThat(calendar.isHoliday(LocalDate.parse("1980-06-17")), is(true));
        assertThat(calendar.isHoliday(LocalDate.parse("1990-06-17")), is(true)); // German Unity Day and Sunday
        assertThat(calendar.isHoliday(LocalDate.parse("1991-06-17")), is(false));

        assertThat(calendar.isHoliday(LocalDate.parse("1989-10-03")), is(false));
        assertThat(calendar.isHoliday(LocalDate.parse("1990-10-03")), is(true));
        assertThat(calendar.isHoliday(LocalDate.parse("1991-10-03")), is(true));
    }

    @Test
    public void testDayOfRepentanceAndPrayer()
    {
        TradeCalendar calendar = TradeCalendarManager.getInstance("de");

        assertThat(calendar.isHoliday(LocalDate.parse("1989-11-22")), is(true)); // latest possible day
        assertThat(calendar.isHoliday(LocalDate.parse("1990-11-21")), is(true));
        assertThat(calendar.isHoliday(LocalDate.parse("1991-11-20")), is(true));
        assertThat(calendar.isHoliday(LocalDate.parse("1992-11-18")), is(true));
        assertThat(calendar.isHoliday(LocalDate.parse("1993-11-17")), is(true));
        assertThat(calendar.isHoliday(LocalDate.parse("1994-11-16")), is(true)); // earliest possible day
        assertThat(calendar.isHoliday(LocalDate.parse("1995-11-22")), is(false));
    }

    @Test
    public void testGermanHolidaysWithTrading()
    {
        TradeCalendar calendar = TradeCalendarManager.getInstance("de");

        // Ascension
        assertThat(calendar.isHoliday(LocalDate.parse("1999-05-13")), is(true));
        assertThat(calendar.isHoliday(LocalDate.parse("2000-06-01")), is(false)); // trading despite public holiday
        assertThat(calendar.isHoliday(LocalDate.parse("2013-05-09")), is(false)); // trading despite public holiday
        assertThat(calendar.isHoliday(LocalDate.parse("2014-05-29")), is(false)); // trading despite public holiday
        assertThat(calendar.isHoliday(LocalDate.parse("2015-05-14")), is(false)); // trading despite public holiday
        assertThat(calendar.isHoliday(LocalDate.parse("2021-05-13")), is(false)); // trading despite public holiday

        // Whit Monday
        assertThat(calendar.isHoliday(LocalDate.parse("1999-05-24")), is(true));
        assertThat(calendar.isHoliday(LocalDate.parse("2000-06-12")), is(false)); // trading despite public holiday
        assertThat(calendar.isHoliday(LocalDate.parse("2013-05-20")), is(false)); // trading despite public holiday
        assertThat(calendar.isHoliday(LocalDate.parse("2014-06-09")), is(false)); // trading despite public holiday
        assertThat(calendar.isHoliday(LocalDate.parse("2015-05-25")), is(true));

        // <NAME>
        assertThat(calendar.isHoliday(LocalDate.parse("1999-06-03")), is(true));
        assertThat(calendar.isHoliday(LocalDate.parse("2000-06-22")), is(false)); // trading despite public holiday
        assertThat(calendar.isHoliday(LocalDate.parse("2013-05-30")), is(false)); // trading despite public holiday
        assertThat(calendar.isHoliday(LocalDate.parse("2014-06-19")), is(false)); // trading despite public holiday
        assertThat(calendar.isHoliday(LocalDate.parse("2015-06-04")), is(false)); // trading despite public holiday
        assertThat(calendar.isHoliday(LocalDate.parse("2021-06-03")), is(false)); // trading despite public holiday

        // German Unity Day
        assertThat(calendar.isHoliday(LocalDate.parse("1999-10-03")), is(true));
        assertThat(calendar.isHoliday(LocalDate.parse("2000-10-03")), is(false)); // trading despite public holiday
        assertThat(calendar.isHoliday(LocalDate.parse("2013-10-03")), is(false)); // trading despite public holiday
        assertThat(calendar.isHoliday(LocalDate.parse("2014-10-03")), is(true));
    }

    @Test
    public void testHolidaysWithCondition()
    {
        TradeCalendar calendar = TradeCalendarManager.getInstance("nyse");

        assertThat(calendar.isHoliday(LocalDate.parse("2019-10-29")), is(false));
        assertThat(calendar.isHoliday(LocalDate.parse("2013-10-29")), is(false));
        assertThat(calendar.isHoliday(LocalDate.parse("2012-10-29")), is(true));
        assertThat(calendar.isHoliday(LocalDate.parse("2011-10-29")), is(true)); // weekend!
        assertThat(calendar.isHoliday(LocalDate.parse("2019-10-29")), is(false));
    }

    @Test
    public void testMovingHolidays()
    {
        TradeCalendar calendar = TradeCalendarManager.getInstance("nyse");

        assertThat(calendar.isHoliday(LocalDate.parse("2018-12-25")), is(true));
        assertThat(calendar.isHoliday(LocalDate.parse("2018-12-26")), is(false));

        assertThat(calendar.isHoliday(LocalDate.parse("2016-12-25")), is(true)); // weekend
        assertThat(calendar.isHoliday(LocalDate.parse("2016-12-26")), is(true));

        assertThat(calendar.isHoliday(LocalDate.parse("2015-12-24")), is(false));
        assertThat(calendar.isHoliday(LocalDate.parse("2015-12-25")), is(true)); // Friday
        assertThat(calendar.isHoliday(LocalDate.parse("2015-12-26")), is(true));

        assertThat(calendar.isHoliday(LocalDate.parse("2010-12-24")), is(true));
        assertThat(calendar.isHoliday(LocalDate.parse("2010-12-25")), is(true)); // Saturday
        assertThat(calendar.isHoliday(LocalDate.parse("2010-12-26")), is(true));

        assertThat(calendar.isHoliday(LocalDate.parse("2021-12-31")), is(false));
        assertThat(calendar.isHoliday(LocalDate.parse("2022-01-01")), is(true)); // Saturday and New Year, not moved
        assertThat(calendar.isHoliday(LocalDate.parse("2022-01-02")), is(true)); // Sunday
        assertThat(calendar.isHoliday(LocalDate.parse("2022-01-03")), is(false));

        assertThat(calendar.isHoliday(LocalDate.parse("2022-12-30")), is(false));
        assertThat(calendar.isHoliday(LocalDate.parse("2022-12-31")), is(true)); // Saturday
        assertThat(calendar.isHoliday(LocalDate.parse("2023-01-01")), is(true)); // Sunday (and New Year)
        assertThat(calendar.isHoliday(LocalDate.parse("2023-01-02")), is(true)); // Monday (New Year observed)
        assertThat(calendar.isHoliday(LocalDate.parse("2023-01-03")), is(false));
    }

    @Test
    public void testNYSE()
    {
        // See https://www.nyse.com/markets/hours-calendars

        TradeCalendar calendar = TradeCalendarManager.getInstance("nyse");

        assertThat(calendar.isHoliday(LocalDate.parse("2001-09-10")), is(false)); // regular Monday
        assertThat(calendar.isHoliday(LocalDate.parse("2001-09-11")), is(true)); // closed after terrorist attacks (9/11)
        assertThat(calendar.isHoliday(LocalDate.parse("2001-09-14")), is(true)); // ... still closed
        assertThat(calendar.isHoliday(LocalDate.parse("2001-09-17")), is(false)); // reopened the following Monday

        assertThat(calendar.isHoliday(LocalDate.parse("2020-01-01")), is(true));
        assertThat(calendar.isHoliday(LocalDate.parse("2020-01-20")), is(true));
        assertThat(calendar.isHoliday(LocalDate.parse("2020-02-17")), is(true));
        assertThat(calendar.isHoliday(LocalDate.parse("2020-04-10")), is(true));
        assertThat(calendar.isHoliday(LocalDate.parse("2020-05-25")), is(true));
        assertThat(calendar.isHoliday(LocalDate.parse("2020-07-03")), is(true));
        assertThat(calendar.isHoliday(LocalDate.parse("2020-09-07")), is(true));
        assertThat(calendar.isHoliday(LocalDate.parse("2020-11-26")), is(true));
        assertThat(calendar.isHoliday(LocalDate.parse("2020-12-25")), is(true));

        assertThat(calendar.isHoliday(LocalDate.parse("2021-01-01")), is(true));
        assertThat(calendar.isHoliday(LocalDate.parse("2021-01-18")), is(true));
        assertThat(calendar.isHoliday(LocalDate.parse("2021-02-15")), is(true));
        assertThat(calendar.isHoliday(LocalDate.parse("2021-04-02")), is(true));
        assertThat(calendar.isHoliday(LocalDate.parse("2021-05-31")), is(true));
        assertThat(calendar.isHoliday(LocalDate.parse("2021-07-05")), is(true));
        assertThat(calendar.isHoliday(LocalDate.parse("2021-09-06")), is(true));
        assertThat(calendar.isHoliday(LocalDate.parse("2021-11-25")), is(true));
        assertThat(calendar.isHoliday(LocalDate.parse("2021-12-24")), is(true));
    }

    @Test
    public void testLSE()
    {
        // See
        // https://www.lseg.com/areas-expertise/our-markets/london-stock-exchange/equities-markets/trading-services/business-days

        TradeCalendar calendar = TradeCalendarManager.getInstance("lse");

        assertThat(calendar.isHoliday(LocalDate.parse("2019-01-01")), is(true));
        assertThat(calendar.isHoliday(LocalDate.parse("2019-04-19")), is(true));
        assertThat(calendar.isHoliday(LocalDate.parse("2019-04-22")), is(true));
        assertThat(calendar.isHoliday(LocalDate.parse("2019-05-06")), is(true));
        assertThat(calendar.isHoliday(LocalDate.parse("2019-05-27")), is(true));
        assertThat(calendar.isHoliday(LocalDate.parse("2019-08-26")), is(true));
        assertThat(calendar.isHoliday(LocalDate.parse("2019-12-25")), is(true));
        assertThat(calendar.isHoliday(LocalDate.parse("2019-12-26")), is(true));
    }

    @Test
    public void testEuronext()
    {
        // See https://www.euronext.com/en/trading-calendars-hours

        TradeCalendar calendar = TradeCalendarManager.getInstance("euronext");

        assertThat(calendar.isHoliday(LocalDate.parse("2019-01-01")), is(true));
        assertThat(calendar.isHoliday(LocalDate.parse("2019-04-19")), is(true));
        assertThat(calendar.isHoliday(LocalDate.parse("2019-04-22")), is(true));
        assertThat(calendar.isHoliday(LocalDate.parse("2019-05-01")), is(true));
        assertThat(calendar.isHoliday(LocalDate.parse("2019-12-25")), is(true));
        assertThat(calendar.isHoliday(LocalDate.parse("2019-12-26")), is(true));
    }

    @Test
    public void testTSX()
    {
        // See https://www.tsx.com/trading/calendars-and-trading-hours/calendar

        TradeCalendar calendar = TradeCalendarManager.getInstance("tsx");

        // New Year
        assertThat(calendar.isHoliday(LocalDate.parse("2011-01-03")), is(true));
        assertThat(calendar.isHoliday(LocalDate.parse("2012-01-02")), is(true));
        assertThat(calendar.isHoliday(LocalDate.parse("2017-01-02")), is(true));

        // Christmas and Boxing Day
        assertThat(calendar.isHoliday(LocalDate.parse("2016-12-26")), is(true));
        assertThat(calendar.isHoliday(LocalDate.parse("2016-12-27")), is(true));

        // Canada Day
        assertThat(calendar.isHoliday(LocalDate.parse("2017-07-03")), is(true));
        assertThat(calendar.isHoliday(LocalDate.parse("2018-07-02")), is(true));

        // 2020: Note Christmas and Boxing Day
        assertThat(calendar.isHoliday(LocalDate.parse("2020-01-01")), is(true));
        assertThat(calendar.isHoliday(LocalDate.parse("2020-02-17")), is(true));
        assertThat(calendar.isHoliday(LocalDate.parse("2020-04-10")), is(true));
        assertThat(calendar.isHoliday(LocalDate.parse("2020-05-18")), is(true));
        assertThat(calendar.isHoliday(LocalDate.parse("2020-07-01")), is(true));
        assertThat(calendar.isHoliday(LocalDate.parse("2020-08-03")), is(true));
        assertThat(calendar.isHoliday(LocalDate.parse("2020-09-07")), is(true));
        assertThat(calendar.isHoliday(LocalDate.parse("2020-10-12")), is(true));
        assertThat(calendar.isHoliday(LocalDate.parse("2020-12-25")), is(true));
        assertThat(calendar.isHoliday(LocalDate.parse("2020-12-28")), is(true));

        // 2021: Note Christmas and Boxing Day
        assertThat(calendar.isHoliday(LocalDate.parse("2021-01-01")), is(true));
        assertThat(calendar.isHoliday(LocalDate.parse("2021-02-15")), is(true));
        assertThat(calendar.isHoliday(LocalDate.parse("2021-04-02")), is(true));
        assertThat(calendar.isHoliday(LocalDate.parse("2021-05-24")), is(true));
        assertThat(calendar.isHoliday(LocalDate.parse("2021-07-01")), is(true));
        assertThat(calendar.isHoliday(LocalDate.parse("2021-08-02")), is(true));
        assertThat(calendar.isHoliday(LocalDate.parse("2021-09-06")), is(true));
        assertThat(calendar.isHoliday(LocalDate.parse("2021-10-11")), is(true));
        assertThat(calendar.isHoliday(LocalDate.parse("2021-12-27")), is(true));
        assertThat(calendar.isHoliday(LocalDate.parse("2021-12-28")), is(true));
    }

    @Test
    public void testEmptyCalendar()
    {
        TradeCalendar calendar = TradeCalendarManager.getInstance(TradeCalendar.EMPTY_CODE);

        // we generate a random day
        long minDay = LocalDate.of(2000, 1, 1).toEpochDay();
        long maxDay = LocalDate.of(2020, 12, 31).toEpochDay();
        long randomDay = ThreadLocalRandom.current().nextLong(minDay, maxDay);
        LocalDate randomDate = LocalDate.ofEpochDay(randomDay);

        // in the empty calendar, every day is a (potential) trading day
        assertThat(calendar.isHoliday(randomDate), is(false));
    }
}
<commit_msg>Test LSE rules for weekend Christmas and New Year<commit_after>package name.abuchen.portfolio.util;

import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.MatcherAssert.assertThat;

import java.time.LocalDate;
import java.util.concurrent.ThreadLocalRandom;

import org.junit.Test;

@SuppressWarnings("nls")
public class TradeCalendarTest
{

    @Test
    public void testEasterHolidays()
    {
        TradeCalendar calendar = TradeCalendarManager.getInstance("de");

        assertThat(calendar.isHoliday(LocalDate.parse("2015-04-02")), is(false));
        assertThat(calendar.isHoliday(LocalDate.parse("2015-04-03")), is(true));
        assertThat(calendar.isHoliday(LocalDate.parse("2015-04-04")), is(true));
        assertThat(calendar.isHoliday(LocalDate.parse("2015-04-05")), is(true));
        assertThat(calendar.isHoliday(LocalDate.parse("2015-04-06")), is(true));
        assertThat(calendar.isHoliday(LocalDate.parse("2015-04-07")), is(false));

        assertThat(calendar.isHoliday(LocalDate.parse("2016-03-25")), is(true));
    }

    @Test
    public void testWeekends()
    {
        TradeCalendar calendar = TradeCalendarManager.getInstance("de");

        assertThat(calendar.isHoliday(LocalDate.parse("2015-01-31")), is(true));
        assertThat(calendar.isHoliday(LocalDate.parse("2015-02-01")), is(true));
    }

    @Test
    public void testFixedPublicHolidays()
    {
        TradeCalendar calendar = TradeCalendarManager.getInstance("de");

        assertThat(calendar.isHoliday(LocalDate.parse("2015-01-01")), is(true));
        assertThat(calendar.isHoliday(LocalDate.parse("2015-05-01")), is(true));
        assertThat(calendar.isHoliday(LocalDate.parse("2015-12-24")), is(true));
        assertThat(calendar.isHoliday(LocalDate.parse("2015-12-25")), is(true));
        assertThat(calendar.isHoliday(LocalDate.parse("2015-12-26")), is(true));

        assertThat(calendar.isHoliday(LocalDate.parse("1980-06-17")), is(true));
        assertThat(calendar.isHoliday(LocalDate.parse("1990-06-17")), is(true)); // German Unity Day and Sunday
        assertThat(calendar.isHoliday(LocalDate.parse("1991-06-17")), is(false));

        assertThat(calendar.isHoliday(LocalDate.parse("1989-10-03")), is(false));
        assertThat(calendar.isHoliday(LocalDate.parse("1990-10-03")), is(true));
        assertThat(calendar.isHoliday(LocalDate.parse("1991-10-03")), is(true));
    }

    @Test
    public void testDayOfRepentanceAndPrayer()
    {
        TradeCalendar calendar = TradeCalendarManager.getInstance("de");

        assertThat(calendar.isHoliday(LocalDate.parse("1989-11-22")), is(true)); // latest possible day
        assertThat(calendar.isHoliday(LocalDate.parse("1990-11-21")), is(true));
        assertThat(calendar.isHoliday(LocalDate.parse("1991-11-20")), is(true));
        assertThat(calendar.isHoliday(LocalDate.parse("1992-11-18")), is(true));
        assertThat(calendar.isHoliday(LocalDate.parse("1993-11-17")), is(true));
        assertThat(calendar.isHoliday(LocalDate.parse("1994-11-16")), is(true)); // earliest possible day
        assertThat(calendar.isHoliday(LocalDate.parse("1995-11-22")), is(false));
    }

    @Test
    public void testGermanHolidaysWithTrading()
    {
        TradeCalendar calendar = TradeCalendarManager.getInstance("de");

        // Ascension
        assertThat(calendar.isHoliday(LocalDate.parse("1999-05-13")), is(true));
        assertThat(calendar.isHoliday(LocalDate.parse("2000-06-01")), is(false)); // trading despite public holiday
        assertThat(calendar.isHoliday(LocalDate.parse("2013-05-09")), is(false)); // trading despite public holiday
        assertThat(calendar.isHoliday(LocalDate.parse("2014-05-29")), is(false)); // trading despite public holiday
        assertThat(calendar.isHoliday(LocalDate.parse("2015-05-14")), is(false)); // trading despite public holiday
        assertThat(calendar.isHoliday(LocalDate.parse("2021-05-13")), is(false)); // trading despite public holiday

        // Whit Monday
        assertThat(calendar.isHoliday(LocalDate.parse("1999-05-24")), is(true));
        assertThat(calendar.isHoliday(LocalDate.parse("2000-06-12")), is(false)); // trading despite public holiday
        assertThat(calendar.isHoliday(LocalDate.parse("2013-05-20")), is(false)); // trading despite public holiday
        assertThat(calendar.isHoliday(LocalDate.parse("2014-06-09")), is(false)); // trading despite public holiday
        assertThat(calendar.isHoliday(LocalDate.parse("2015-05-25")), is(true));

        // <NAME>
        assertThat(calendar.isHoliday(LocalDate.parse("1999-06-03")), is(true));
        assertThat(calendar.isHoliday(LocalDate.parse("2000-06-22")), is(false)); // trading despite public holiday
        assertThat(calendar.isHoliday(LocalDate.parse("2013-05-30")), is(false)); // trading despite public holiday
        assertThat(calendar.isHoliday(LocalDate.parse("2014-06-19")), is(false)); // trading despite public holiday
        assertThat(calendar.isHoliday(LocalDate.parse("2015-06-04")), is(false)); // trading despite public holiday
        assertThat(calendar.isHoliday(LocalDate.parse("2021-06-03")), is(false)); // trading despite public holiday

        // German Unity Day
        assertThat(calendar.isHoliday(LocalDate.parse("1999-10-03")), is(true));
        assertThat(calendar.isHoliday(LocalDate.parse("2000-10-03")), is(false)); // trading despite public holiday
        assertThat(calendar.isHoliday(LocalDate.parse("2013-10-03")), is(false)); // trading despite public holiday
        assertThat(calendar.isHoliday(LocalDate.parse("2014-10-03")), is(true));
    }

    @Test
    public void testHolidaysWithCondition()
    {
        TradeCalendar calendar = TradeCalendarManager.getInstance("nyse");

        assertThat(calendar.isHoliday(LocalDate.parse("2019-10-29")), is(false));
        assertThat(calendar.isHoliday(LocalDate.parse("2013-10-29")), is(false));
        assertThat(calendar.isHoliday(LocalDate.parse("2012-10-29")), is(true));
        assertThat(calendar.isHoliday(LocalDate.parse("2011-10-29")), is(true)); // weekend!
        assertThat(calendar.isHoliday(LocalDate.parse("2019-10-29")), is(false));
    }

    @Test
    public void testMovingHolidays()
    {
        TradeCalendar calendar = TradeCalendarManager.getInstance("nyse");

        assertThat(calendar.isHoliday(LocalDate.parse("2018-12-25")), is(true));
        assertThat(calendar.isHoliday(LocalDate.parse("2018-12-26")), is(false));

        assertThat(calendar.isHoliday(LocalDate.parse("2016-12-25")), is(true)); // weekend
        assertThat(calendar.isHoliday(LocalDate.parse("2016-12-26")), is(true));

        assertThat(calendar.isHoliday(LocalDate.parse("2015-12-24")), is(false));
        assertThat(calendar.isHoliday(LocalDate.parse("2015-12-25")), is(true)); // Friday
        assertThat(calendar.isHoliday(LocalDate.parse("2015-12-26")), is(true));

        assertThat(calendar.isHoliday(LocalDate.parse("2010-12-24")), is(true));
        assertThat(calendar.isHoliday(LocalDate.parse("2010-12-25")), is(true)); // Saturday
        assertThat(calendar.isHoliday(LocalDate.parse("2010-12-26")), is(true));

        assertThat(calendar.isHoliday(LocalDate.parse("2021-12-31")), is(false));
        assertThat(calendar.isHoliday(LocalDate.parse("2022-01-01")), is(true)); // Saturday and New Year, not moved
        assertThat(calendar.isHoliday(LocalDate.parse("2022-01-02")), is(true)); // Sunday
        assertThat(calendar.isHoliday(LocalDate.parse("2022-01-03")), is(false));

        assertThat(calendar.isHoliday(LocalDate.parse("2022-12-30")), is(false));
        assertThat(calendar.isHoliday(LocalDate.parse("2022-12-31")), is(true)); // Saturday
        assertThat(calendar.isHoliday(LocalDate.parse("2023-01-01")), is(true)); // Sunday (and New Year)
        assertThat(calendar.isHoliday(LocalDate.parse("2023-01-02")), is(true)); // Monday (New Year observed)
        assertThat(calendar.isHoliday(LocalDate.parse("2023-01-03")), is(false));
    }

    @Test
    public void testNYSE()
    {
        // See https://www.nyse.com/markets/hours-calendars

        TradeCalendar calendar = TradeCalendarManager.getInstance("nyse");

        assertThat(calendar.isHoliday(LocalDate.parse("2001-09-10")), is(false)); // regular Monday
        assertThat(calendar.isHoliday(LocalDate.parse("2001-09-11")), is(true)); // closed after terrorist attacks (9/11)
        assertThat(calendar.isHoliday(LocalDate.parse("2001-09-14")), is(true)); // ... still closed
        assertThat(calendar.isHoliday(LocalDate.parse("2001-09-17")), is(false)); // reopened the following Monday

        assertThat(calendar.isHoliday(LocalDate.parse("2020-01-01")), is(true));
        assertThat(calendar.isHoliday(LocalDate.parse("2020-01-20")), is(true));
        assertThat(calendar.isHoliday(LocalDate.parse("2020-02-17")), is(true));
        assertThat(calendar.isHoliday(LocalDate.parse("2020-04-10")), is(true));
        assertThat(calendar.isHoliday(LocalDate.parse("2020-05-25")), is(true));
        assertThat(calendar.isHoliday(LocalDate.parse("2020-07-03")), is(true));
        assertThat(calendar.isHoliday(LocalDate.parse("2020-09-07")), is(true));
        assertThat(calendar.isHoliday(LocalDate.parse("2020-11-26")), is(true));
        assertThat(calendar.isHoliday(LocalDate.parse("2020-12-25")), is(true));

        assertThat(calendar.isHoliday(LocalDate.parse("2021-01-01")), is(true));
        assertThat(calendar.isHoliday(LocalDate.parse("2021-01-18")), is(true));
        assertThat(calendar.isHoliday(LocalDate.parse("2021-02-15")), is(true));
        assertThat(calendar.isHoliday(LocalDate.parse("2021-04-02")), is(true));
        assertThat(calendar.isHoliday(LocalDate.parse("2021-05-31")), is(true));
        assertThat(calendar.isHoliday(LocalDate.parse("2021-07-05")), is(true));
        assertThat(calendar.isHoliday(LocalDate.parse("2021-09-06")), is(true));
        assertThat(calendar.isHoliday(LocalDate.parse("2021-11-25")), is(true));
        assertThat(calendar.isHoliday(LocalDate.parse("2021-12-24")), is(true));
    }

    @Test
    public void testLSE()
    {
        // See https://www.londonstockexchange.com/trade/trading-access/business-days

        TradeCalendar calendar = TradeCalendarManager.getInstance("lse");

        assertThat(calendar.isHoliday(LocalDate.parse("2019-01-01")), is(true));
        assertThat(calendar.isHoliday(LocalDate.parse("2019-04-19")), is(true));
        assertThat(calendar.isHoliday(LocalDate.parse("2019-04-22")), is(true));
        assertThat(calendar.isHoliday(LocalDate.parse("2019-05-06")), is(true));
        assertThat(calendar.isHoliday(LocalDate.parse("2019-05-27")), is(true));
        assertThat(calendar.isHoliday(LocalDate.parse("2019-08-26")), is(true));
        assertThat(calendar.isHoliday(LocalDate.parse("2019-12-25")), is(true));
        assertThat(calendar.isHoliday(LocalDate.parse("2019-12-26")), is(true));

        assertThat(calendar.isHoliday(LocalDate.parse("2021-12-24")), is(false));
        assertThat(calendar.isHoliday(LocalDate.parse("2021-12-25")), is(true)); // Saturday and Christmas Day
        assertThat(calendar.isHoliday(LocalDate.parse("2021-12-26")), is(true)); // Sunday and Boxing Day
        assertThat(calendar.isHoliday(LocalDate.parse("2021-12-27")), is(true)); // Monday, substitute for holiday
        assertThat(calendar.isHoliday(LocalDate.parse("2021-12-28")), is(true)); // Tuesday, substitute for holiday
        assertThat(calendar.isHoliday(LocalDate.parse("2021-12-29")), is(false));
        assertThat(calendar.isHoliday(LocalDate.parse("2021-12-30")), is(false));
        assertThat(calendar.isHoliday(LocalDate.parse("2021-12-31")), is(false));
        assertThat(calendar.isHoliday(LocalDate.parse("2022-01-01")), is(true)); // Saturday and New Year
        assertThat(calendar.isHoliday(LocalDate.parse("2022-01-02")), is(true)); // Sunday
        assertThat(calendar.isHoliday(LocalDate.parse("2022-01-03")), is(true)); // Monday, substitute for holiday
        assertThat(calendar.isHoliday(LocalDate.parse("2022-01-04")), is(false));
    }

    @Test
    public void testEuronext()
    {
        // See https://www.euronext.com/en/trading-calendars-hours

        TradeCalendar calendar = TradeCalendarManager.getInstance("euronext");

        assertThat(calendar.isHoliday(LocalDate.parse("2019-01-01")), is(true));
        assertThat(calendar.isHoliday(LocalDate.parse("2019-04-19")), is(true));
        assertThat(calendar.isHoliday(LocalDate.parse("2019-04-22")), is(true));
        assertThat(calendar.isHoliday(LocalDate.parse("2019-05-01")), is(true));
        assertThat(calendar.isHoliday(LocalDate.parse("2019-12-25")), is(true));
        assertThat(calendar.isHoliday(LocalDate.parse("2019-12-26")), is(true));
    }

    @Test
    public void testTSX()
    {
        // See https://www.tsx.com/trading/calendars-and-trading-hours/calendar

        TradeCalendar calendar = TradeCalendarManager.getInstance("tsx");

        // New Year
        assertThat(calendar.isHoliday(LocalDate.parse("2011-01-03")), is(true));
        assertThat(calendar.isHoliday(LocalDate.parse("2012-01-02")), is(true));
        assertThat(calendar.isHoliday(LocalDate.parse("2017-01-02")), is(true));

        // Christmas and Boxing Day
        assertThat(calendar.isHoliday(LocalDate.parse("2016-12-26")), is(true));
        assertThat(calendar.isHoliday(LocalDate.parse("2016-12-27")), is(true));

        // Canada Day
        assertThat(calendar.isHoliday(LocalDate.parse("2017-07-03")), is(true));
        assertThat(calendar.isHoliday(LocalDate.parse("2018-07-02")), is(true));

        // 2020: Note Christmas and Boxing Day
        assertThat(calendar.isHoliday(LocalDate.parse("2020-01-01")), is(true));
        assertThat(calendar.isHoliday(LocalDate.parse("2020-02-17")), is(true));
        assertThat(calendar.isHoliday(LocalDate.parse("2020-04-10")), is(true));
        assertThat(calendar.isHoliday(LocalDate.parse("2020-05-18")), is(true));
        assertThat(calendar.isHoliday(LocalDate.parse("2020-07-01")), is(true));
        assertThat(calendar.isHoliday(LocalDate.parse("2020-08-03")), is(true));
        assertThat(calendar.isHoliday(LocalDate.parse("2020-09-07")), is(true));
        assertThat(calendar.isHoliday(LocalDate.parse("2020-10-12")), is(true));
        assertThat(calendar.isHoliday(LocalDate.parse("2020-12-25")), is(true));
        assertThat(calendar.isHoliday(LocalDate.parse("2020-12-28")), is(true));

        // 2021: Note Christmas and Boxing Day
        assertThat(calendar.isHoliday(LocalDate.parse("2021-01-01")), is(true));
        assertThat(calendar.isHoliday(LocalDate.parse("2021-02-15")), is(true));
        assertThat(calendar.isHoliday(LocalDate.parse("2021-04-02")), is(true));
        assertThat(calendar.isHoliday(LocalDate.parse("2021-05-24")), is(true));
        assertThat(calendar.isHoliday(LocalDate.parse("2021-07-01")), is(true));
        assertThat(calendar.isHoliday(LocalDate.parse("2021-08-02")), is(true));
        assertThat(calendar.isHoliday(LocalDate.parse("2021-09-06")), is(true));
        assertThat(calendar.isHoliday(LocalDate.parse("2021-10-11")), is(true));
        assertThat(calendar.isHoliday(LocalDate.parse("2021-12-27")), is(true));
        assertThat(calendar.isHoliday(LocalDate.parse("2021-12-28")), is(true));
    }

    @Test
    public void testEmptyCalendar()
    {
        TradeCalendar calendar = TradeCalendarManager.getInstance(TradeCalendar.EMPTY_CODE);

        // we generate a random day
        long minDay = LocalDate.of(2000, 1, 1).toEpochDay();
        long maxDay = LocalDate.of(2020, 12, 31).toEpochDay();
        long randomDay = ThreadLocalRandom.current().nextLong(minDay, maxDay);
        LocalDate randomDate = LocalDate.ofEpochDay(randomDay);

        // in the empty calendar, every day is a (potential) trading day
        assertThat(calendar.isHoliday(randomDate), is(false));
    }
}

{'fraction_non_alphanumeric': 0.1709016659104168, 'fraction_numerical': 0.0747390937965904, 'mean_word_length': 4.0723327305605785, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 8, 'lorem ipsum': 0, 'www.': 8, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2896780', 'n_tokens_mistral': 10882, 'n_tokens_neox': 9698, 'n_words': 1149}