import random


def randomly_assign_train_test(features, labels, test_size=0.1):
    """
    Splits up data into train and test subsets.

    :param features: 2D array storing features
    :type: features: list or np.array

    :param labels: 1D array storing labels
    :type: labels: list or np.array

    :param test_size: proportion of the data to be used for testing
    :type: test_size: float

    :return: training features, training labels, testing features, testing labels
    :rtype:  tuple containing np.arrays
    """
    data = list(zip(list(features), list(labels)))
    random.shuffle(data)

    # Unzips data
    shuffled_features, shuffled_labels = zip(*data)

    split_index = int(len(shuffled_features) * test_size)

    train_features, test_features = shuffled_features[split_index:], shuffled_features[:split_index]
    train_labels, test_labels = shuffled_labels[split_index:], shuffled_labels[:split_index]
    return train_features, test_features, train_labels, test_labels