(* Copyright (C) 2013--2024  Petter A. Urkedal <paurkedal@gmail.com>
 *
 * This library is free software; you can redistribute it and/or modify it
 * under the terms of the GNU Lesser General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or (at your
 * option) any later version, with the LGPL-3.0 Linking Exception.
 *
 * This library is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public
 * License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public License
 * and the LGPL-3.0 Linking Exception along with this library.  If not, see
 * <http://www.gnu.org/licenses/> and <https://spdx.org>, respectively.
 *)

module A = Alcotest.V1
include Unprime_list

let test_list () =
  A.(check (list int)) "filter_map"
    [1; 2; 5]
    (List.filter_map (fun x -> if x >= 0 then Some x else None) [1; 2; -3; -4; 5]);
  A.(check (list int)) "flatten_map"
    [3; 2; 1; 0; 1; 0; 2; 1; 0]
    (List.flatten_map (fun n -> Prime_int.fold_to List.cons n []) [4; 2; 3]);
  A.(check (list int)) "rev_flatten"
    [-1; 0; 1; 2; 3; 4; 5]
    (List.rev_flatten [[5; 4; 3]; [2; 1]; [0; -1]]);

  (* concat *)
  A.(check (list int)) "interfix 1" [1] (List.interfix 0 [1]);
  A.(check (list int)) "interfix 2" [1; 0; 2] (List.interfix 0 [1; 2]);
  A.(check (list int)) "interfix 3" [1; 0; 2; 0; 3] (List.interfix 0 [1; 2; 3])

let test_cases = [
  A.test_case "list" `Quick test_list;
]
