// Path: mug/src/main/java/com/google/mu/function/BiComparator.java
// static <K, V, T> BiComparator<K, V> comparing(
//     BiFunction<? super K, ? super V, ? extends T> function, Comparator<? super T> ordering) {
//   requireNonNull(function);
//   requireNonNull(ordering);
//   return (k1, v1, k2, v2) -> ordering.compare(function.apply(k1, v1), function.apply(k2, v2));
// }
// 
// Path: mug/src/main/java/com/google/mu/function/BiComparator.java
// static <K, T extends Comparable<T>> BiComparator<K, Object> comparingKey(
//     Function<? super K, ? extends T> function) {
//   return comparingKey(function, naturalOrder());
// }
// 
// Path: mug/src/main/java/com/google/mu/function/BiComparator.java
// static <V, T extends Comparable<T>> BiComparator<Object, V> comparingValue(
//     Function<? super V, ? extends T> function) {
//   return comparingValue(function, naturalOrder());
// }


import static com.google.common.truth.Truth.assertThat;
import static com.google.mu.function.BiComparator.comparing;
import static com.google.mu.function.BiComparator.comparingKey;
import static com.google.mu.function.BiComparator.comparingValue;
import static java.util.Comparator.naturalOrder;
import static java.util.Comparator.reverseOrder;
import static java.util.Objects.requireNonNull;
import java.util.Comparator;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.JUnit4;
import com.google.common.testing.NullPointerTester;
/*****************************************************************************
 * ------------------------------------------------------------------------- *
 * Licensed under the Apache License, Version 2.0 (the "License");           *
 * you may not use this file except in compliance with the License.          *
 * You may obtain a copy of the License at                                   *
 *                                                                           *
 * http://www.apache.org/licenses/LICENSE-2.0                                *
 *                                                                           *
 * Unless required by applicable law or agreed to in writing, software       *
 * distributed under the License is distributed on an "AS IS" BASIS,         *
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  *
 * See the License for the specific language governing permissions and       *
 * limitations under the License.                                            *
 *****************************************************************************/
package com.google.mu.function;





@RunWith(JUnit4.class)
public class BiComparatorTest {
  @Test public void comparingByFunction() {
    assertThat(comparing(Integer::sum).compare(1, 3, 2, 2)).isEqualTo(0);
    assertThat(comparing(Integer::sum).compare(1, 3, 0, 5)).isLessThan(0);
    assertThat(comparing(Integer::sum).compare(1, 4, 2, 2)).isGreaterThan(0);
  }

  @Test public void comparingKeyByFunction() {
    assertThat(comparingKey(Object::toString).compare(1, 3, 2, 2)).isLessThan(0);
    assertThat(comparingKey(Object::toString).compare(2, 3, 2, 2)).isEqualTo(0);
    assertThat(comparingKey(Object::toString).compare(3, 3, 2, 2)).isGreaterThan(0);
  }

  @Test public void comparingKeyByComparator() {
    assertThat(BiComparator.<Integer>comparingKey(reverseOrder()).compare(1, "", 2, null))
        .isGreaterThan(0);
    assertThat(BiComparator.<Integer>comparingKey(reverseOrder()).compare(2, "", 2, null))
        .isEqualTo(0);
    assertThat(BiComparator.<Integer>comparingKey(reverseOrder()).compare(2, "", 1, null))
        .isLessThan(0);
  }

  @Test public void comparingValueByFunction() {
// Path: mug/src/main/java/com/google/mu/function/BiComparator.java
// static <K, V, T> BiComparator<K, V> comparing(
//     BiFunction<? super K, ? super V, ? extends T> function, Comparator<? super T> ordering) {
//   requireNonNull(function);
//   requireNonNull(ordering);
//   return (k1, v1, k2, v2) -> ordering.compare(function.apply(k1, v1), function.apply(k2, v2));
// }
// 
// Path: mug/src/main/java/com/google/mu/function/BiComparator.java
// static <K, T extends Comparable<T>> BiComparator<K, Object> comparingKey(
//     Function<? super K, ? extends T> function) {
//   return comparingKey(function, naturalOrder());
// }
// 
// Path: mug/src/main/java/com/google/mu/function/BiComparator.java
// static <V, T extends Comparable<T>> BiComparator<Object, V> comparingValue(
//     Function<? super V, ? extends T> function) {
//   return comparingValue(function, naturalOrder());
// }


// Path: mug/src/test/java/com/google/mu/function/BiComparatorTest.java
import static com.google.common.truth.Truth.assertThat;
import static com.google.mu.function.BiComparator.comparing;
import static com.google.mu.function.BiComparator.comparingKey;
import static com.google.mu.function.BiComparator.comparingValue;
import static java.util.Comparator.naturalOrder;
import static java.util.Comparator.reverseOrder;
import static java.util.Objects.requireNonNull;
import java.util.Comparator;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.JUnit4;
import com.google.common.testing.NullPointerTester;

/*****************************************************************************
 * ------------------------------------------------------------------------- *
 * Licensed under the Apache License, Version 2.0 (the "License");           *
 * you may not use this file except in compliance with the License.          *
 * You may obtain a copy of the License at                                   *
 *                                                                           *
 * http://www.apache.org/licenses/LICENSE-2.0                                *
 *                                                                           *
 * Unless required by applicable law or agreed to in writing, software       *
 * distributed under the License is distributed on an "AS IS" BASIS,         *
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  *
 * See the License for the specific language governing permissions and       *
 * limitations under the License.                                            *
 *****************************************************************************/
package com.google.mu.function;





@RunWith(JUnit4.class)
public class BiComparatorTest {
  @Test public void comparingByFunction() {
    assertThat(comparing(Integer::sum).compare(1, 3, 2, 2)).isEqualTo(0);
    assertThat(comparing(Integer::sum).compare(1, 3, 0, 5)).isLessThan(0);
    assertThat(comparing(Integer::sum).compare(1, 4, 2, 2)).isGreaterThan(0);
  }

  @Test public void comparingKeyByFunction() {
    assertThat(comparingKey(Object::toString).compare(1, 3, 2, 2)).isLessThan(0);
    assertThat(comparingKey(Object::toString).compare(2, 3, 2, 2)).isEqualTo(0);
    assertThat(comparingKey(Object::toString).compare(3, 3, 2, 2)).isGreaterThan(0);
  }

  @Test public void comparingKeyByComparator() {
    assertThat(BiComparator.<Integer>comparingKey(reverseOrder()).compare(1, "", 2, null))
        .isGreaterThan(0);
    assertThat(BiComparator.<Integer>comparingKey(reverseOrder()).compare(2, "", 2, null))
        .isEqualTo(0);
    assertThat(BiComparator.<Integer>comparingKey(reverseOrder()).compare(2, "", 1, null))
        .isLessThan(0);
  }

  @Test public void comparingValueByFunction() {
    assertThat(comparingValue(Object::toString).compare(1, 3, 2, 2)).isGreaterThan(0);