from typing import Tuple


def calculate_rules_indices(rules_idx: list, fold_id: int, num_folds: int) -> Tuple[list, list]:
    """
    Calculates the indices of the samples which are to be included in training and test sets for k-fold cross validation

    :param rules_idx: all rules indices (shuffled) that are to be splitted into cw training & cw test set rules
    :param fold_id: number of a current hold-out fold
    :param num_folds: the whole number of folds the data should be splitted into

    :return: two arrays containing indices of rules that will be used for cw training and cw test set accordingly
    """
    test_rules_idx = rules_idx[fold_id::num_folds]
    train_rules_idx = [rule_id for rule_id in rules_idx if rule_id not in test_rules_idx]

    if not set(test_rules_idx).isdisjoint(set(train_rules_idx)):
        raise ValueError("Splitting into train and test rules is done incorrectly.")

    return train_rules_idx, test_rules_idx