import math
import random


def train_test(data, val_ratio=0.2, test_ratio=0.2, shuffle=True, seed=42):
    """Split a list into training and test sets, with specified ratio.

    By default, the data is shuffled with a fixed random seed.
    The data is not mutated.

    :param data: list of data objects
    :param val_ratio: ratio of data to take for validation set
    :param test_ratio: ratio of data to take for test set
    :param shuffle: if true, the data is shuffled before being split
    :param seed: random seed for the shuffle
    :returns: triple of lists (training set, validation set, test set)

    """
    n = len(data)
    k_val = math.floor((1 - val_ratio - test_ratio) * n)
    k_test = math.floor((1 - test_ratio) * n)
    if shuffle:
        random.seed(42)
        data_shuffled = random.sample(data, k=n)
    else:
        data_shuffled = data

    return data_shuffled[:k_val], data_shuffled[k_val:k_test], data_shuffled[k_test:]