import "./order-by";
import "./array";
import { It } from "../test-utils";

It(
  "Sorts a basic sequence of numbers",
  (s) => s.order_by().array(),
  [1, 2, 3, 4],
  [2, 3, 1, 4]
);
It(
  "Sorts a basic sequence of strings",
  (s) => s.order_by().array(),
  ["Dec", "Feb", "Jan", "March"],
  ["March", "Jan", "Feb", "Dec"]
);
It(
  "Sorts a sequence of complex objects with selector",
  (s) => s.order_by((s) => s.test).array(),
  [{ test: 1 }, { test: 2 }, { test: 3 }, { test: 4 }],
  [{ test: 2 }, { test: 3 }, { test: 1 }, { test: 4 }]
);
It(
  "Sorts a sequence of complex objects custom comparitor",
  (s) =>
    s
      .order_by(
        (s) => s,
        (a, b) => a.test > b.test
      )
      .array(),
  [{ test: 1 }, { test: 2 }, { test: 3 }, { test: 4 }],
  [{ test: 2 }, { test: 3 }, { test: 1 }, { test: 4 }]
);

It(
  "Sorts a basic sequence of numbers descending",
  (s) => s.order_by("descending").array(),
  [4, 3, 2, 1],
  [2, 3, 1, 4]
);
It(
  "Sorts a basic sequence of strings descending",
  (s) => s.order_by("descending").array(),
  ["March", "Jan", "Feb", "Dec"],
  ["March", "Jan", "Feb", "Dec"]
);
It(
  "Sorts a sequence of complex objects with selector descending",
  (s) => s.order_by((s) => s.test, "descending").array(),
  [{ test: 4 }, { test: 3 }, { test: 2 }, { test: 1 }],
  [{ test: 2 }, { test: 3 }, { test: 1 }, { test: 4 }]
);
It(
  "Sorts a sequence of complex objects custom comparitor descending",
  (s) =>
    s
      .order_by(
        (s) => s,
        (a, b) => a.test > b.test,
        "descending"
      )
      .array(),
  [{ test: 4 }, { test: 3 }, { test: 2 }, { test: 1 }],
  [{ test: 2 }, { test: 3 }, { test: 1 }, { test: 4 }]
);
