using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;

namespace LabelerCore.Model.CrossValidation
{
    public class LeaveOneOut : IEnumerable
    {
        private int _n;

        public LeaveOneOut(int[] y)
        {
            _n = y.Length;
        }

        public int Length
        {
            get
            {
                return _n;
            }
        }

        //Yields tuple<train list indices, test list indices>
        public IEnumerator GetEnumerator()
        {
            var ind = Enumerable.Range(0, _n);
            for (int i = 0; i < _n; i++)
            {
                var test = ind.Skip(i).Take(1).ToList();
                var train = ind.ToList();
                train.RemoveAt(i);
                yield return new Tuple<List<int>, List<int>>(train, test);
            }
        }
    }

}
