'Test that we account for midweek holidays. Monday 01/20 is a holiday.
Ensure that the trigger date for that week is adjusted
appropriately, or thrown out if not enough trading days. Also, test
that if we start the simulation on a day where we miss the trigger
for that week, that the trigger is recalculated for next week.'

@parameter_space(rule_offset=(0, 1, 2, 3, 4), start_offset=(0, 1, 2, 3, 4), type=('week_start', 'week_end'))
def test_edge_cases_for_TradingDayOfWeek(self, rule_offset, start_offset, type):

    sim_start = (pd.Timestamp('2014-01-06', tz='UTC') + timedelta(days=start_offset))
    delta = timedelta(days=start_offset)
    jan_minutes = self.cal.minutes_for_sessions_in_range((pd.Timestamp('2014-01-06', tz='UTC') + delta), pd.Timestamp('2014-01-31', tz='UTC'))
    if (type == 'week_start'):
        rule = NthTradingDayOfWeek
        trigger_periods = [pd.Timestamp('2014-01-06', tz='UTC'), pd.Timestamp('2014-01-13', tz='UTC'), pd.Timestamp('2014-01-21', tz='UTC'), pd.Timestamp('2014-01-27', tz='UTC')]
        trigger_periods = [(x + timedelta(days=rule_offset)) for x in trigger_periods]
    else:
        rule = NDaysBeforeLastTradingDayOfWeek
        trigger_periods = [pd.Timestamp('2014-01-10', tz='UTC'), pd.Timestamp('2014-01-17', tz='UTC'), pd.Timestamp('2014-01-24', tz='UTC'), pd.Timestamp('2014-01-31', tz='UTC')]
        trigger_periods = [(x - timedelta(days=rule_offset)) for x in trigger_periods]
    rule.cal = self.cal
    should_trigger = rule(rule_offset).should_trigger
    if (rule_offset == 4):
        del trigger_periods[2]
    trigger_periods = [x for x in trigger_periods if (x >= sim_start)]
    trigger_minutes = self.cal.minutes_for_session(trigger_periods[0])
    for period in trigger_periods[1:]:
        trigger_minutes += self.cal.minutes_for_session(period)
    expected_n_triggered = len(trigger_minutes)
    trigger_minutes_iter = iter(trigger_minutes)
    n_triggered = 0
    for m in jan_minutes:
        if should_trigger(m):
            self.assertEqual(m, next(trigger_minutes_iter))
            n_triggered += 1
    self.assertEqual(n_triggered, expected_n_triggered)
