// Path: src/main/java/org/smallibs/suitcase/cases/core/Cases.java
// static <T> Case.WithoutCapture<T, T> Any() {
//     return new Case0<T, T>(Optional::of).$();
// }
// 
// Path: src/main/java/org/smallibs/suitcase/cases/core/Cases.java
// static <T> Case.WithoutCapture<T, T> Constant(T value) {
//     return new Case0<T, T>(p -> Objects.deepEquals(p, value) ? Optional.of(p) : Optional.empty()).$();
// }
// 
// Path: src/main/java/org/smallibs/suitcase/cases/core/Cases.java
// static <T> Var.WithoutInnerCapture<T, T> Var() {
//     return Var(Any());
// }
// 
// Path: src/main/java/org/smallibs/suitcase/cases/lang/Lists.java
// static <T> Case2<List<T>, List<T>, T, List<T>> Cons() {
//     return new Case2<>(
//             l -> !l.isEmpty() ? Optional.of(l) : Optional.empty(),
//             l -> l.get(0),
//             l -> l.subList(1, l.size())
//     );
// }
// 
// Path: src/main/java/org/smallibs/suitcase/cases/lang/Lists.java
// static <T> Case.WithoutCapture<List<T>, List<T>> Empty() {
//     return new Case0<List<T>, List<T>>(
//             p -> p.isEmpty() ? Optional.of(p) : Optional.empty()
//     ).$();
// }
// 
// Path: src/main/java/org/smallibs/suitcase/utils/Functions.java
// public static <C1, C2, R> Function<Pair<C1, C2>, R> function(Function2<C1, C2, R> function) {
//     return params -> function.apply(params._1, params._2);
// }


import static org.smallibs.suitcase.utils.Functions.function;
import junit.framework.TestCase;
import org.junit.Test;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import static org.smallibs.suitcase.cases.core.Cases.Any;
import static org.smallibs.suitcase.cases.core.Cases.Constant;
import static org.smallibs.suitcase.cases.core.Cases.Var;
import static org.smallibs.suitcase.cases.lang.Lists.Cons;
import static org.smallibs.suitcase.cases.lang.Lists.Empty;
/*
 * Copyright (C)2015 D. Plaindoux.
 *
 * This program 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 2, or (at your option) any
 * later version.
 *
 * This program 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
 * along with this program; see the file COPYING.  If not, write to
 * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
 */

package org.smallibs.suitcase.match;





public class ListMatcherTest {
    @Test
    public void shouldMatchLisContainingAnObject() throws MatchingException {
        final Matcher<List<Integer>, Boolean> isEmpty = Matcher.create();

        isEmpty.caseOf(Cons(Constant(1), Any())).then(true);
        isEmpty.caseOf(Any()).then(false);

        TestCase.assertTrue(isEmpty.match(Collections.singletonList(1)));
        TestCase.assertFalse(isEmpty.match(Collections.emptyList()));
        TestCase.assertFalse(isEmpty.match(Arrays.asList(2, 3)));
    }

    @Test
    public void shouldComputeListSizeWithAdHocPatternObject() throws MatchingException {
        final Matcher<List<?>, Integer> sizeOfMatcher = Matcher.create();

// Path: src/main/java/org/smallibs/suitcase/cases/core/Cases.java
// static <T> Case.WithoutCapture<T, T> Any() {
//     return new Case0<T, T>(Optional::of).$();
// }
// 
// Path: src/main/java/org/smallibs/suitcase/cases/core/Cases.java
// static <T> Case.WithoutCapture<T, T> Constant(T value) {
//     return new Case0<T, T>(p -> Objects.deepEquals(p, value) ? Optional.of(p) : Optional.empty()).$();
// }
// 
// Path: src/main/java/org/smallibs/suitcase/cases/core/Cases.java
// static <T> Var.WithoutInnerCapture<T, T> Var() {
//     return Var(Any());
// }
// 
// Path: src/main/java/org/smallibs/suitcase/cases/lang/Lists.java
// static <T> Case2<List<T>, List<T>, T, List<T>> Cons() {
//     return new Case2<>(
//             l -> !l.isEmpty() ? Optional.of(l) : Optional.empty(),
//             l -> l.get(0),
//             l -> l.subList(1, l.size())
//     );
// }
// 
// Path: src/main/java/org/smallibs/suitcase/cases/lang/Lists.java
// static <T> Case.WithoutCapture<List<T>, List<T>> Empty() {
//     return new Case0<List<T>, List<T>>(
//             p -> p.isEmpty() ? Optional.of(p) : Optional.empty()
//     ).$();
// }
// 
// Path: src/main/java/org/smallibs/suitcase/utils/Functions.java
// public static <C1, C2, R> Function<Pair<C1, C2>, R> function(Function2<C1, C2, R> function) {
//     return params -> function.apply(params._1, params._2);
// }


// Path: src/test/java/org/smallibs/suitcase/match/ListMatcherTest.java
import static org.smallibs.suitcase.utils.Functions.function;
import junit.framework.TestCase;
import org.junit.Test;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import static org.smallibs.suitcase.cases.core.Cases.Any;
import static org.smallibs.suitcase.cases.core.Cases.Constant;
import static org.smallibs.suitcase.cases.core.Cases.Var;
import static org.smallibs.suitcase.cases.lang.Lists.Cons;
import static org.smallibs.suitcase.cases.lang.Lists.Empty;

/*
 * Copyright (C)2015 D. Plaindoux.
 *
 * This program 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 2, or (at your option) any
 * later version.
 *
 * This program 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
 * along with this program; see the file COPYING.  If not, write to
 * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
 */

package org.smallibs.suitcase.match;





public class ListMatcherTest {
    @Test
    public void shouldMatchLisContainingAnObject() throws MatchingException {
        final Matcher<List<Integer>, Boolean> isEmpty = Matcher.create();

        isEmpty.caseOf(Cons(Constant(1), Any())).then(true);
        isEmpty.caseOf(Any()).then(false);

        TestCase.assertTrue(isEmpty.match(Collections.singletonList(1)));
        TestCase.assertFalse(isEmpty.match(Collections.emptyList()));
        TestCase.assertFalse(isEmpty.match(Arrays.asList(2, 3)));
    }

    @Test
    public void shouldComputeListSizeWithAdHocPatternObject() throws MatchingException {
        final Matcher<List<?>, Integer> sizeOfMatcher = Matcher.create();

        sizeOfMatcher.caseOf(Empty()).then(0);