Best JavaScript code snippet using fast-check-monorepo
index.js
Source:index.js  
1'use strict';2const assert = require ('assert');3const vm = require ('vm');4const laws = require ('fantasy-laws');5const jsc = require ('jsverify');6const Identity = require ('sanctuary-identity');7const Maybe = require ('sanctuary-maybe');8const Pair = require ('sanctuary-pair');9const show = require ('sanctuary-show');10const type = require ('sanctuary-type-identifiers');11const Useless = require ('sanctuary-useless');12const Z = require ('..');13const {version} = require ('../package.json');14const Lazy = require ('./Lazy');15const List = require ('./List');16const Sum = require ('./Sum');17const eq = require ('./eq');18const {withUnstableArraySort} = require ('./quicksort');19const {Nil, Cons} = List;20const {Nothing, Just} = Maybe;21//  mapArb :: (a -> b) -> Arbitrary a -> Arbitrary b22const mapArb = f => arb => jsc.bless ({generator: arb.generator.map (f)});23//  smapArb :: (a -> b) -> (b -> a) -> Arbitrary a -> Arbitrary b24const smapArb = f => g => arb => arb.smap (f, g, show);25//  Lazy$of :: a -> Lazy a26function Lazy$of(x) {27  eq (arguments.length, Lazy$of.length);28  return Z.of (Lazy, x);29}30//  ListArb :: Arbitrary a -> Arbitrary (List a)31const ListArb = arb => smapArb (arrayToList) (listToArray) (jsc.array (arb));32//  MaybeArb :: Arbitrary a -> Arbitrary (Maybe a)33const MaybeArb = arb => jsc.oneof (jsc.constant (Nothing), mapArb (Just) (arb));34//  Point :: () -> Point35function Point() {36  eq (arguments.length, Point.length);37  if (!(this instanceof Point)) return new Point ();38}39Point.prototype.x = 0;40Point.prototype.y = 0;41//  abs :: Number -> Number42function abs(x) {43  eq (arguments.length, abs.length);44  return Math.abs (x);45}46//  add :: (Number, Number) -> Number47function add(x, y) {48  eq (arguments.length, add.length);49  return x + y;50}51//  append :: a -> Array a -> Array a52function append(x) {53  eq (arguments.length, append.length);54  return function append$1(xs) {55    eq (arguments.length, append$1.length);56    return xs.concat ([x]);57  };58}59//  args :: (Any...) -> Arguments60function args() {61  // eslint-disable-next-line prefer-rest-params62  return arguments;63}64//  arrayToList :: Array a -> List a65const arrayToList = xs => {66  let list = Nil;67  for (let idx = 0; idx < xs.length; idx += 1) list = Cons (xs[idx], list);68  return list;69};70//  compose :: (b -> c) -> (a -> b) -> a -> c71function compose(f) {72  eq (arguments.length, compose.length);73  return function compose$1(g) {74    eq (arguments.length, compose$1.length);75    return function compose$2(x) {76      eq (arguments.length, compose$2.length);77      return f (g (x));78    };79  };80}81//  concat :: Array a -> Array a -> Array a82function concat(xs) {83  eq (arguments.length, concat.length);84  return function concat$1(ys) {85    eq (arguments.length, concat$1.length);86    return xs.concat (ys);87  };88}89//  double :: a -> Array2 a a90function double(x) {91  eq (arguments.length, double.length);92  return [x, x];93}94//  gt :: Number -> Number -> Boolean95function gt(x) {96  eq (arguments.length, gt.length);97  return function gt$1(y) {98    eq (arguments.length, gt$1.length);99    return y > x;100  };101}102//  identInc :: Number -> Identity Number103function identInc(x) {104  eq (arguments.length, identInc.length);105  return Identity (x + 1);106}107//  identity :: a -> a108function identity(x) {109  eq (arguments.length, identity.length);110  return x;111}112//  inc :: Number -> Number113function inc(x) {114  eq (arguments.length, inc.length);115  return x + 1;116}117//  joinWith :: String -> Array String -> String118function joinWith(s) {119  eq (arguments.length, joinWith.length);120  return function joinWith$1(ss) {121    eq (arguments.length, joinWith$1.length);122    return ss.join (s);123  };124}125//  length :: List a -> Integer126function length(xs) {127  eq (arguments.length, length.length);128  return xs.length;129}130//  listToArray :: List a -> Array a131function listToArray(xs) {132  eq (arguments.length, listToArray.length);133  const result = [];134  for (let list = xs; list.isCons; list = list.tail) result.push (list.head);135  return result;136}137//  lt :: Number -> Number -> Boolean138function lt(x) {139  eq (arguments.length, lt.length);140  return function lt$1(y) {141    eq (arguments.length, lt$1.length);142    return y < x;143  };144}145const node1 = {id: 1, rels: []};146const node2 = {id: 2, rels: []};147node1.rels.push ({type: 'child', value: node2});148node2.rels.push ({type: 'parent', value: node1});149//  odd :: Integer -> Boolean150function odd(x) {151  eq (arguments.length, odd.length);152  return x % 2 === 1;153}154//  ones :: Array2 Number (Array2 Number (Array2 Number ...))155const ones = [1]; ones.push (ones);156//  ones_ :: Array2 Number (Array2 Number (Array2 Number ...))157const ones_ = [1]; ones_.push ([1, ones_]);158//  parseInt_ :: Integer -> String -> Maybe Integer159function parseInt_(radix) {160  eq (arguments.length, parseInt_.length);161  return function parseInt$1(s) {162    eq (arguments.length, parseInt$1.length);163    const n = parseInt (s, radix);164    return isNaN (n) ? Nothing : Just (n);165  };166}167//  pow :: Number -> Number -> Number168function pow(base) {169  eq (arguments.length, pow.length);170  return function pow$1(exp) {171    eq (arguments.length, pow$1.length);172    return Math.pow (base, exp);173  };174}175//  product :: Foldable f => f Number -> Number176function product(xs) {177  eq (arguments.length, product.length);178  return Z.reduce ((x, y) => x * y, 1, xs);179}180//  range :: Integer -> Array Integer181function range(n) {182  eq (arguments.length, range.length);183  const result = [];184  for (let m = 0; m < n; m += 1) result.push (m);185  return result;186}187//  repeat :: Integer -> a -> Array a188function repeat(n) {189  eq (arguments.length, repeat.length);190  return function repeat$1(x) {191    eq (arguments.length, repeat$1.length);192    const result = [];193    for (let m = 0; m < n; m += 1) result.push (x);194    return result;195  };196}197//  splitOn :: String -> String -> Array String198function splitOn(sep) {199  eq (arguments.length, splitOn.length);200  return function splitOn$1(s) {201    eq (arguments.length, splitOn$1.length);202    return s.split (sep);203  };204}205//  square :: Number -> Number206function square(x) {207  eq (arguments.length, square.length);208  return x * x;209}210//  sum :: Foldable f => f Number -> Number211function sum(xs) {212  eq (arguments.length, sum.length);213  return Z.reduce (add, 0, xs);214}215//  toUpper :: String -> String216function toUpper(s) {217  eq (arguments.length, toUpper.length);218  return s.toUpperCase ();219}220//  wrap :: String -> String -> String -> String221function wrap(before) {222  eq (arguments.length, wrap.length);223  return function wrap$1(after) {224    eq (arguments.length, wrap$1.length);225    return function wrap$2(s) {226      eq (arguments.length, wrap$2.length);227      return before + s + after;228    };229  };230}231const makeValues = () => ({232  Array: ['?', '!'],233  Boolean: new Boolean (true),234  Date: new Date (0),235  Function: x => x + 1,236  Number: new Number (42),237  Object: {'?': '!'},238  RegExp: /foo/,239  String: new String ('?!'),240});241const domesticValues = makeValues ();242const alienValues = vm.runInNewContext (String (makeValues)) ();243test ('test assumptions', () => {244  eq (domesticValues.Array.constructor === alienValues.Array.constructor, false);245  eq (domesticValues.Boolean.constructor === alienValues.Boolean.constructor, false);246  eq (domesticValues.Date.constructor === alienValues.Date.constructor, false);247  eq (domesticValues.Function.constructor === alienValues.Function.constructor, false);248  eq (domesticValues.Number.constructor === alienValues.Number.constructor, false);249  eq (domesticValues.RegExp.constructor === alienValues.RegExp.constructor, false);250  eq (domesticValues.String.constructor === alienValues.String.constructor, false);251});252test ('TypeClass', () => {253  eq (typeof Z.TypeClass, 'function');254  eq (Z.TypeClass.length, 4);255  //  hasMethod :: String -> a -> Boolean256  const hasMethod = name => x => x != null && typeof x[name] === 'function';257  //  Foo :: TypeClass258  const Foo = Z.TypeClass (259    'my-package/Foo',260    'http://example.com/my-package#Foo',261    [],262    hasMethod ('foo')263  );264  //  Bar :: TypeClass265  const Bar = Z.TypeClass (266    'my-package/Bar',267    'http://example.com/my-package#Bar',268    [Foo],269    hasMethod ('bar')270  );271  eq (type (Foo), 'sanctuary-type-classes/TypeClass@1');272  eq (Foo.name, 'my-package/Foo');273  eq (Foo.url, 'http://example.com/my-package#Foo');274  eq (Foo.test (null), false);275  eq (Foo.test ({}), false);276  eq (Foo.test ({foo: () => {}}), true);277  eq (Foo.test ({bar: () => {}}), false);278  eq (Foo.test ({foo: () => {}, bar: () => {}}), true);279  eq (type (Bar), 'sanctuary-type-classes/TypeClass@1');280  eq (Bar.name, 'my-package/Bar');281  eq (Bar.url, 'http://example.com/my-package#Bar');282  eq (Bar.test (null), false);283  eq (Bar.test ({}), false);284  eq (Bar.test ({foo: () => {}}), false);285  eq (Bar.test ({bar: () => {}}), false);286  eq (Bar.test ({foo: () => {}, bar: () => {}}), true);287});288test ('Setoid', () => {289  eq (type (Z.Setoid), 'sanctuary-type-classes/TypeClass@1');290  eq (Z.Setoid.name, 'sanctuary-type-classes/Setoid');291  eq (Z.Setoid.url, `https://github.com/sanctuary-js/sanctuary-type-classes/tree/v${version}#Setoid`);292  eq (Z.Setoid.test (null), true);293  eq (Z.Setoid.test (''), true);294  eq (Z.Setoid.test ([]), true);295  eq (Z.Setoid.test ({}), true);296  eq (Z.Setoid.test (Useless), false);297  eq (Z.Setoid.test ([Useless]), false);298  eq (Z.Setoid.test ({foo: Useless}), false);299});300test ('Ord', () => {301  eq (type (Z.Ord), 'sanctuary-type-classes/TypeClass@1');302  eq (Z.Ord.name, 'sanctuary-type-classes/Ord');303  eq (Z.Ord.url, `https://github.com/sanctuary-js/sanctuary-type-classes/tree/v${version}#Ord`);304  eq (Z.Ord.test (null), true);305  eq (Z.Ord.test (''), true);306  eq (Z.Ord.test ([]), true);307  eq (Z.Ord.test ({}), true);308  eq (Z.Ord.test (Math.abs), false);309  eq (Z.Ord.test ([Math.abs]), false);310  eq (Z.Ord.test ({foo: Math.abs}), false);311});312test ('Semigroupoid', () => {313  eq (type (Z.Semigroupoid), 'sanctuary-type-classes/TypeClass@1');314  eq (Z.Semigroupoid.name, 'sanctuary-type-classes/Semigroupoid');315  eq (Z.Semigroupoid.url, `https://github.com/sanctuary-js/sanctuary-type-classes/tree/v${version}#Semigroupoid`);316  eq (Z.Semigroupoid.test (null), false);317  eq (Z.Semigroupoid.test (''), false);318  eq (Z.Semigroupoid.test ([]), false);319  eq (Z.Semigroupoid.test ({}), false);320  eq (Z.Semigroupoid.test (Math.abs), true);321});322test ('Category', () => {323  eq (type (Z.Category), 'sanctuary-type-classes/TypeClass@1');324  eq (Z.Category.name, 'sanctuary-type-classes/Category');325  eq (Z.Category.url, `https://github.com/sanctuary-js/sanctuary-type-classes/tree/v${version}#Category`);326  eq (Z.Category.test (null), false);327  eq (Z.Category.test (''), false);328  eq (Z.Category.test ([]), false);329  eq (Z.Category.test ({}), false);330  eq (Z.Category.test (Math.abs), true);331});332test ('Semigroup', () => {333  eq (type (Z.Semigroup), 'sanctuary-type-classes/TypeClass@1');334  eq (Z.Semigroup.name, 'sanctuary-type-classes/Semigroup');335  eq (Z.Semigroup.url, `https://github.com/sanctuary-js/sanctuary-type-classes/tree/v${version}#Semigroup`);336  eq (Z.Semigroup.test (null), false);337  eq (Z.Semigroup.test (''), true);338  eq (Z.Semigroup.test ([]), true);339  eq (Z.Semigroup.test ({}), true);340});341test ('Monoid', () => {342  eq (type (Z.Monoid), 'sanctuary-type-classes/TypeClass@1');343  eq (Z.Monoid.name, 'sanctuary-type-classes/Monoid');344  eq (Z.Monoid.url, `https://github.com/sanctuary-js/sanctuary-type-classes/tree/v${version}#Monoid`);345  eq (Z.Monoid.test (null), false);346  eq (Z.Monoid.test (''), true);347  eq (Z.Monoid.test ([]), true);348  eq (Z.Monoid.test ({}), true);349});350test ('Group', () => {351  eq (type (Z.Group), 'sanctuary-type-classes/TypeClass@1');352  eq (Z.Group.name, 'sanctuary-type-classes/Group');353  eq (Z.Group.url, `https://github.com/sanctuary-js/sanctuary-type-classes/tree/v${version}#Group`);354  eq (Z.Group.test (null), false);355  eq (Z.Group.test (''), false);356  eq (Z.Group.test ([]), false);357  eq (Z.Group.test ({}), false);358  eq (Z.Group.test (Sum (0)), true);359});360test ('Filterable', () => {361  eq (type (Z.Filterable), 'sanctuary-type-classes/TypeClass@1');362  eq (Z.Filterable.name, 'sanctuary-type-classes/Filterable');363  eq (Z.Filterable.url, `https://github.com/sanctuary-js/sanctuary-type-classes/tree/v${version}#Filterable`);364  eq (Z.Filterable.test (null), false);365  eq (Z.Filterable.test (''), false);366  eq (Z.Filterable.test ([]), true);367  eq (Z.Filterable.test ({}), true);368});369test ('Functor', () => {370  eq (type (Z.Functor), 'sanctuary-type-classes/TypeClass@1');371  eq (Z.Functor.name, 'sanctuary-type-classes/Functor');372  eq (Z.Functor.url, `https://github.com/sanctuary-js/sanctuary-type-classes/tree/v${version}#Functor`);373  eq (Z.Functor.test (null), false);374  eq (Z.Functor.test (''), false);375  eq (Z.Functor.test ([]), true);376  eq (Z.Functor.test ({}), true);377});378test ('Bifunctor', () => {379  eq (type (Z.Bifunctor), 'sanctuary-type-classes/TypeClass@1');380  eq (Z.Bifunctor.name, 'sanctuary-type-classes/Bifunctor');381  eq (Z.Bifunctor.url, `https://github.com/sanctuary-js/sanctuary-type-classes/tree/v${version}#Bifunctor`);382  eq (Z.Bifunctor.test (null), false);383  eq (Z.Bifunctor.test (''), false);384  eq (Z.Bifunctor.test ([]), false);385  eq (Z.Bifunctor.test ({}), false);386  eq (Z.Bifunctor.test (Pair ('abc') (123)), true);387});388test ('Profunctor', () => {389  eq (type (Z.Profunctor), 'sanctuary-type-classes/TypeClass@1');390  eq (Z.Profunctor.name, 'sanctuary-type-classes/Profunctor');391  eq (Z.Profunctor.url, `https://github.com/sanctuary-js/sanctuary-type-classes/tree/v${version}#Profunctor`);392  eq (Z.Profunctor.test (null), false);393  eq (Z.Profunctor.test (''), false);394  eq (Z.Profunctor.test ([]), false);395  eq (Z.Profunctor.test ({}), false);396  eq (Z.Profunctor.test (Math.abs), true);397});398test ('Apply', () => {399  eq (type (Z.Apply), 'sanctuary-type-classes/TypeClass@1');400  eq (Z.Apply.name, 'sanctuary-type-classes/Apply');401  eq (Z.Apply.url, `https://github.com/sanctuary-js/sanctuary-type-classes/tree/v${version}#Apply`);402  eq (Z.Apply.test (null), false);403  eq (Z.Apply.test (''), false);404  eq (Z.Apply.test ([]), true);405  eq (Z.Apply.test ({}), true);406});407test ('Applicative', () => {408  eq (type (Z.Applicative), 'sanctuary-type-classes/TypeClass@1');409  eq (Z.Applicative.name, 'sanctuary-type-classes/Applicative');410  eq (Z.Applicative.url, `https://github.com/sanctuary-js/sanctuary-type-classes/tree/v${version}#Applicative`);411  eq (Z.Applicative.test (null), false);412  eq (Z.Applicative.test (''), false);413  eq (Z.Applicative.test ([]), true);414  eq (Z.Applicative.test ({}), false);415});416test ('Chain', () => {417  eq (type (Z.Chain), 'sanctuary-type-classes/TypeClass@1');418  eq (Z.Chain.name, 'sanctuary-type-classes/Chain');419  eq (Z.Chain.url, `https://github.com/sanctuary-js/sanctuary-type-classes/tree/v${version}#Chain`);420  eq (Z.Chain.test (null), false);421  eq (Z.Chain.test (''), false);422  eq (Z.Chain.test ([]), true);423  eq (Z.Chain.test ({}), false);424});425test ('ChainRec', () => {426  eq (type (Z.ChainRec), 'sanctuary-type-classes/TypeClass@1');427  eq (Z.ChainRec.name, 'sanctuary-type-classes/ChainRec');428  eq (Z.ChainRec.url, `https://github.com/sanctuary-js/sanctuary-type-classes/tree/v${version}#ChainRec`);429  eq (Z.ChainRec.test (null), false);430  eq (Z.ChainRec.test (''), false);431  eq (Z.ChainRec.test ([]), true);432  eq (Z.ChainRec.test ({}), false);433});434test ('Monad', () => {435  eq (type (Z.Monad), 'sanctuary-type-classes/TypeClass@1');436  eq (Z.Monad.name, 'sanctuary-type-classes/Monad');437  eq (Z.Monad.url, `https://github.com/sanctuary-js/sanctuary-type-classes/tree/v${version}#Monad`);438  eq (Z.Monad.test (null), false);439  eq (Z.Monad.test (''), false);440  eq (Z.Monad.test ([]), true);441  eq (Z.Monad.test ({}), false);442});443test ('Alt', () => {444  eq (type (Z.Alt), 'sanctuary-type-classes/TypeClass@1');445  eq (Z.Alt.name, 'sanctuary-type-classes/Alt');446  eq (Z.Alt.url, `https://github.com/sanctuary-js/sanctuary-type-classes/tree/v${version}#Alt`);447  eq (Z.Alt.test (null), false);448  eq (Z.Alt.test (''), false);449  eq (Z.Alt.test ([]), true);450  eq (Z.Alt.test ({}), true);451});452test ('Plus', () => {453  eq (type (Z.Plus), 'sanctuary-type-classes/TypeClass@1');454  eq (Z.Plus.name, 'sanctuary-type-classes/Plus');455  eq (Z.Plus.url, `https://github.com/sanctuary-js/sanctuary-type-classes/tree/v${version}#Plus`);456  eq (Z.Plus.test (null), false);457  eq (Z.Plus.test (''), false);458  eq (Z.Plus.test ([]), true);459  eq (Z.Plus.test ({}), true);460});461test ('Alternative', () => {462  eq (type (Z.Alternative), 'sanctuary-type-classes/TypeClass@1');463  eq (Z.Alternative.name, 'sanctuary-type-classes/Alternative');464  eq (Z.Alternative.url, `https://github.com/sanctuary-js/sanctuary-type-classes/tree/v${version}#Alternative`);465  eq (Z.Alternative.test (null), false);466  eq (Z.Alternative.test (''), false);467  eq (Z.Alternative.test ([]), true);468  eq (Z.Alternative.test ({}), false);469});470test ('Foldable', () => {471  eq (type (Z.Foldable), 'sanctuary-type-classes/TypeClass@1');472  eq (Z.Foldable.name, 'sanctuary-type-classes/Foldable');473  eq (Z.Foldable.url, `https://github.com/sanctuary-js/sanctuary-type-classes/tree/v${version}#Foldable`);474  eq (Z.Foldable.test (null), false);475  eq (Z.Foldable.test (''), false);476  eq (Z.Foldable.test ([]), true);477  eq (Z.Foldable.test ({}), true);478});479test ('Traversable', () => {480  eq (type (Z.Traversable), 'sanctuary-type-classes/TypeClass@1');481  eq (Z.Traversable.name, 'sanctuary-type-classes/Traversable');482  eq (Z.Traversable.url, `https://github.com/sanctuary-js/sanctuary-type-classes/tree/v${version}#Traversable`);483  eq (Z.Traversable.test (null), false);484  eq (Z.Traversable.test (''), false);485  eq (Z.Traversable.test ([]), true);486  eq (Z.Traversable.test ({}), true);487});488test ('Extend', () => {489  eq (type (Z.Extend), 'sanctuary-type-classes/TypeClass@1');490  eq (Z.Extend.name, 'sanctuary-type-classes/Extend');491  eq (Z.Extend.url, `https://github.com/sanctuary-js/sanctuary-type-classes/tree/v${version}#Extend`);492  eq (Z.Extend.test (null), false);493  eq (Z.Extend.test (''), false);494  eq (Z.Extend.test ([]), true);495  eq (Z.Extend.test ({}), false);496});497test ('Comonad', () => {498  eq (type (Z.Comonad), 'sanctuary-type-classes/TypeClass@1');499  eq (Z.Comonad.name, 'sanctuary-type-classes/Comonad');500  eq (Z.Comonad.url, `https://github.com/sanctuary-js/sanctuary-type-classes/tree/v${version}#Comonad`);501  eq (Z.Comonad.test (null), false);502  eq (Z.Comonad.test (''), false);503  eq (Z.Comonad.test ([]), false);504  eq (Z.Comonad.test ({}), false);505  eq (Z.Comonad.test (Identity (0)), true);506});507test ('Contravariant', () => {508  eq (type (Z.Contravariant), 'sanctuary-type-classes/TypeClass@1');509  eq (Z.Contravariant.name, 'sanctuary-type-classes/Contravariant');510  eq (Z.Contravariant.url, `https://github.com/sanctuary-js/sanctuary-type-classes/tree/v${version}#Contravariant`);511  eq (Z.Contravariant.test (null), false);512  eq (Z.Contravariant.test (''), false);513  eq (Z.Contravariant.test ([]), false);514  eq (Z.Contravariant.test ({}), false);515  eq (Z.Contravariant.test (Math.abs), true);516});517test ('equals', () => {518  const {nestedSetoidArb} = jsc.letrec (tie => ({519    builtinSetoidArb: jsc.record ({520      value: tie ('nestedSetoidArb'),521    }),522    noSetoidArb: jsc.record ({523      'value': tie ('nestedSetoidArb'),524      '@@type': jsc.constant ('sanctuary-type-classes/NoSetoid@1'),525      '@@show': jsc.constant (function() { return `NoSetoid (${show (this.value)})`; }),526    }),527    customSetoidArb: jsc.record ({528      'value': tie ('nestedSetoidArb'),529      '@@type': jsc.constant ('sanctuary-type-classes/CustomSetoid@1'),530      '@@show': jsc.constant (function() { return `CustomSetoid (${show (this.value)})`; }),531      'fantasy-land/equals': jsc.constant (function(other) {532        return Z.equals (this.value, other.value);533      }),534    }),535    nestedSetoidArb: jsc.oneof ([536      tie ('builtinSetoidArb'),537      tie ('noSetoidArb'),538      tie ('customSetoidArb'),539      jsc.nat,540    ]),541  }));542  nestedSetoidArb.show = show;543  eq (Z.equals.length, 2);544  eq (Z.equals (null, null), true);545  eq (Z.equals (null, undefined), false);546  eq (Z.equals (undefined, null), false);547  eq (Z.equals (undefined, undefined), true);548  eq (Z.equals (false, false), true);549  eq (Z.equals (false, true), false);550  eq (Z.equals (true, false), false);551  eq (Z.equals (true, true), true);552  eq (Z.equals (new Boolean (false), new Boolean (false)), true);553  eq (Z.equals (new Boolean (false), new Boolean (true)), false);554  eq (Z.equals (new Boolean (true), new Boolean (false)), false);555  eq (Z.equals (new Boolean (true), new Boolean (true)), true);556  eq (Z.equals (false, new Boolean (false)), false);557  eq (Z.equals (new Boolean (false), false), false);558  eq (Z.equals (true, new Boolean (true)), false);559  eq (Z.equals (new Boolean (true), true), false);560  eq (Z.equals (0, 0), true);561  eq (Z.equals (0, -0), true);562  eq (Z.equals (-0, 0), true);563  eq (Z.equals (-0, -0), true);564  eq (Z.equals (NaN, NaN), true);565  eq (Z.equals (Infinity, Infinity), true);566  eq (Z.equals (Infinity, -Infinity), false);567  eq (Z.equals (-Infinity, Infinity), false);568  eq (Z.equals (-Infinity, -Infinity), true);569  eq (Z.equals (NaN, Math.PI), false);570  eq (Z.equals (Math.PI, NaN), false);571  eq (Z.equals (new Number (0), new Number (0)), true);572  eq (Z.equals (new Number (0), new Number (-0)), true);573  eq (Z.equals (new Number (-0), new Number (0)), true);574  eq (Z.equals (new Number (-0), new Number (-0)), true);575  eq (Z.equals (new Number (NaN), new Number (NaN)), true);576  eq (Z.equals (new Number (Infinity), new Number (Infinity)), true);577  eq (Z.equals (new Number (Infinity), new Number (-Infinity)), false);578  eq (Z.equals (new Number (-Infinity), new Number (Infinity)), false);579  eq (Z.equals (new Number (-Infinity), new Number (-Infinity)), true);580  eq (Z.equals (new Number (NaN), new Number (Math.PI)), false);581  eq (Z.equals (new Number (Math.PI), new Number (NaN)), false);582  eq (Z.equals (42, new Number (42)), false);583  eq (Z.equals (new Number (42), 42), false);584  eq (Z.equals (NaN, new Number (NaN)), false);585  eq (Z.equals (new Number (NaN), NaN), false);586  eq (Z.equals (new Date (0), new Date (0)), true);587  eq (Z.equals (new Date (0), new Date (1)), false);588  eq (Z.equals (new Date (1), new Date (0)), false);589  eq (Z.equals (new Date (1), new Date (1)), true);590  eq (Z.equals (new Date (NaN), new Date (NaN)), true);591  eq (Z.equals (/abc/, /xyz/), false);592  eq (Z.equals (/abc/, /abc/g), false);593  eq (Z.equals (/abc/, /abc/i), false);594  eq (Z.equals (/abc/, /abc/m), false);595  eq (Z.equals (/abc/, /abc/), true);596  eq (Z.equals (/abc/g, /abc/g), true);597  eq (Z.equals (/abc/i, /abc/i), true);598  eq (Z.equals (/abc/m, /abc/m), true);599  eq (Z.equals ('', ''), true);600  eq (Z.equals ('abc', 'abc'), true);601  eq (Z.equals ('abc', 'xyz'), false);602  eq (Z.equals (new String (''), new String ('')), true);603  eq (Z.equals (new String ('abc'), new String ('abc')), true);604  eq (Z.equals (new String ('abc'), new String ('xyz')), false);605  eq (Z.equals ('abc', new String ('abc')), false);606  eq (Z.equals (new String ('abc'), 'abc'), false);607  eq (Z.equals ([], []), true);608  eq (Z.equals ([1, 2], [1, 2]), true);609  eq (Z.equals ([1, 2, 3], [1, 2]), false);610  eq (Z.equals ([1, 2], [1, 2, 3]), false);611  eq (Z.equals ([1, 2], [2, 1]), false);612  eq (Z.equals ([0], [-0]), true);613  eq (Z.equals ([NaN], [NaN]), true);614  eq (Z.equals (ones, ones), true);615  eq (Z.equals (ones, [1, [1, [1, [1, []]]]]), false);616  eq (Z.equals (ones, [1, [1, [1, [1, [0, ones]]]]]), false);617  eq (Z.equals (ones, [1, [1, [1, [1, [1, ones]]]]]), true);618  eq (Z.equals (ones, ones_), true);619  eq (Z.equals (ones_, ones), true);620  eq (Z.equals (args (), args ()), true);621  eq (Z.equals (args (1, 2), args (1, 2)), true);622  eq (Z.equals (args (1, 2, 3), args (1, 2)), false);623  eq (Z.equals (args (1, 2), args (1, 2, 3)), false);624  eq (Z.equals (args (1, 2), args (2, 1)), false);625  eq (Z.equals (args (0), args (-0)), true);626  eq (Z.equals (args (NaN), args (NaN)), true);627  eq (Z.equals (new Error ('abc'), new Error ('abc')), true);628  eq (Z.equals (new Error ('abc'), new Error ('xyz')), false);629  eq (Z.equals (new TypeError ('abc'), new TypeError ('abc')), true);630  eq (Z.equals (new TypeError ('abc'), new TypeError ('xyz')), false);631  eq (Z.equals (new Error ('abc'), new TypeError ('abc')), false);632  eq (Z.equals (new TypeError ('abc'), new Error ('abc')), false);633  eq (Z.equals ({}, {}), true);634  eq (Z.equals ({x: 1, y: 2}, {y: 2, x: 1}), true);635  eq (Z.equals ({x: 1, y: 2, z: 3}, {x: 1, y: 2}), false);636  eq (Z.equals ({x: 1, y: 2}, {x: 1, y: 2, z: 3}), false);637  eq (Z.equals ({x: 1, y: 2}, {x: 2, y: 1}), false);638  eq (Z.equals ({x: 0}, {x: -0}), true);639  eq (Z.equals ({x: NaN}, {x: NaN}), true);640  eq (Z.equals (node1, node1), true);641  eq (Z.equals (node2, node2), true);642  eq (Z.equals (node1, node2), false);643  eq (Z.equals (node2, node1), false);644  eq (Z.equals (Math.sin, Math.sin), true);645  eq (Z.equals (Math.sin, Math.cos), false);646  eq (Z.equals (Identity (Identity (Identity (0))), Identity (Identity (Identity (0)))), true);647  eq (Z.equals (Identity (Identity (Identity (0))), Identity (Identity (Identity (1)))), false);648  eq (Z.equals (Useless, Useless), true);649  eq (Z.equals (Array.prototype, Array.prototype), true);650  eq (Z.equals (Nothing.constructor, Maybe), true);651  eq (Z.equals ((Just (0)).constructor, Maybe), true);652  eq (Z.equals (Lazy$of (0), Lazy$of (0)), false);653  eq (Z.equals (alienValues.Array, domesticValues.Array), true);654  eq (Z.equals (alienValues.Boolean, domesticValues.Boolean), true);655  eq (Z.equals (alienValues.Date, domesticValues.Date), true);656  eq (Z.equals (alienValues.Number, domesticValues.Number), true);657  eq (Z.equals (alienValues.RegExp, domesticValues.RegExp), true);658  eq (Z.equals (alienValues.String, domesticValues.String), true);659  const $0 = {z: 0};660  const $1 = {z: 1};661  $0.a = $1;662  $1.a = $0;663  eq (Z.equals ($0, $0), true);664  eq (Z.equals ($0, $1), false);665  eq (Z.equals ($1, $0), false);666  jsc.assert (jsc.forall (nestedSetoidArb, x => Z.equals (x, x)));667});668test ('lt', () => {669  eq (Z.lt.length, 2);670  eq (Z.lt (0, 0), false);671  eq (Z.lt (0, 1), true);672  eq (Z.lt (1, 0), false);673  eq (Z.lt ('abc', 123), false);674});675test ('lte', () => {676  eq (Z.lte.length, 2);677  eq (Z.lte (null, null), true);678  eq (Z.lte (null, undefined), false);679  eq (Z.lte (undefined, null), false);680  eq (Z.lte (undefined, undefined), true);681  eq (Z.lte (false, false), true);682  eq (Z.lte (false, true), true);683  eq (Z.lte (true, false), false);684  eq (Z.lte (true, true), true);685  eq (Z.lte (new Boolean (false), new Boolean (false)), true);686  eq (Z.lte (new Boolean (false), new Boolean (true)), true);687  eq (Z.lte (new Boolean (true), new Boolean (false)), false);688  eq (Z.lte (new Boolean (true), new Boolean (true)), true);689  eq (Z.lte (false, new Boolean (false)), false);690  eq (Z.lte (new Boolean (false), false), false);691  eq (Z.lte (true, new Boolean (true)), false);692  eq (Z.lte (new Boolean (true), true), false);693  eq (Z.lte (42, 42), true);694  eq (Z.lte (42, 43), true);695  eq (Z.lte (43, 42), false);696  eq (Z.lte (0, 0), true);697  eq (Z.lte (0, -0), true);698  eq (Z.lte (-0, 0), true);699  eq (Z.lte (-0, -0), true);700  eq (Z.lte (NaN, NaN), true);701  eq (Z.lte (Infinity, Infinity), true);702  eq (Z.lte (Infinity, -Infinity), false);703  eq (Z.lte (-Infinity, Infinity), true);704  eq (Z.lte (-Infinity, -Infinity), true);705  eq (Z.lte (NaN, Math.PI), true);706  eq (Z.lte (Math.PI, NaN), false);707  eq (Z.lte (new Number (0), new Number (0)), true);708  eq (Z.lte (new Number (0), new Number (-0)), true);709  eq (Z.lte (new Number (-0), new Number (0)), true);710  eq (Z.lte (new Number (-0), new Number (-0)), true);711  eq (Z.lte (new Number (NaN), new Number (NaN)), true);712  eq (Z.lte (new Number (Infinity), new Number (Infinity)), true);713  eq (Z.lte (new Number (Infinity), new Number (-Infinity)), false);714  eq (Z.lte (new Number (-Infinity), new Number (Infinity)), true);715  eq (Z.lte (new Number (-Infinity), new Number (-Infinity)), true);716  eq (Z.lte (new Number (NaN), new Number (Math.PI)), true);717  eq (Z.lte (new Number (Math.PI), new Number (NaN)), false);718  eq (Z.lte (42, new Number (42)), false);719  eq (Z.lte (new Number (42), 42), false);720  eq (Z.lte (new Date (0), new Date (0)), true);721  eq (Z.lte (new Date (0), new Date (1)), true);722  eq (Z.lte (new Date (1), new Date (0)), false);723  eq (Z.lte (new Date (1), new Date (1)), true);724  eq (Z.lte (new Date (NaN), new Date (NaN)), true);725  eq (Z.lte ('', ''), true);726  eq (Z.lte ('abc', 'abc'), true);727  eq (Z.lte ('abc', 'xyz'), true);728  eq (Z.lte (new String (''), new String ('')), true);729  eq (Z.lte (new String ('abc'), new String ('abc')), true);730  eq (Z.lte (new String ('abc'), new String ('xyz')), true);731  eq (Z.lte ('abc', new String ('abc')), false);732  eq (Z.lte (new String ('abc'), 'abc'), false);733  eq (Z.lte ([], []), true);734  eq (Z.lte ([1, 2], [1, 2]), true);735  eq (Z.lte ([1, 2, 3], [1, 2]), false);736  eq (Z.lte ([1, 2], [1, 2, 3]), true);737  eq (Z.lte ([1, 2], [2]), true);738  eq (Z.lte ([], [undefined]), true);739  eq (Z.lte ([undefined], []), false);740  eq (Z.lte ([1], [undefined]), false);741  eq (Z.lte ([undefined], [1]), false);742  eq (Z.lte ([0], [-0]), true);743  eq (Z.lte ([NaN], [NaN]), true);744  eq (Z.lte (ones, ones), true);745  eq (Z.lte (ones, [1, [1, [1, [1, []]]]]), false);746  eq (Z.lte (ones, [1, [1, [1, [1, [0, ones]]]]]), false);747  eq (Z.lte (ones, [1, [1, [1, [1, [1, ones]]]]]), true);748  eq (Z.lte (ones, ones_), true);749  eq (Z.lte (ones_, ones), true);750  eq (Z.lte (args (), args ()), true);751  eq (Z.lte (args (1, 2), args (1, 2)), true);752  eq (Z.lte (args (1, 2, 3), args (1, 2)), false);753  eq (Z.lte (args (1, 2), args (1, 2, 3)), true);754  eq (Z.lte (args (1, 2), args (2, 1)), true);755  eq (Z.lte (args (0), args (-0)), true);756  eq (Z.lte (args (NaN), args (NaN)), true);757  eq (Z.lte ({}, {}), true);758  eq (Z.lte ({a: 0}, {z: 0}), true);759  eq (Z.lte ({z: 0}, {a: 0}), false);760  eq (Z.lte ({x: 1, y: 2}, {y: 2, x: 1}), true);761  eq (Z.lte ({x: 1, y: 2, z: 3}, {x: 1, y: 2}), false);762  eq (Z.lte ({x: 1, y: 2}, {x: 1, y: 2, z: 3}), true);763  eq (Z.lte ({x: 1, y: 2, z: 3}, {x: 1, y: 2, z: undefined}), false);764  eq (Z.lte ({x: 1, y: 2, z: undefined}, {x: 1, y: 2, z: 3}), false);765  eq (Z.lte ({x: 1, y: 1}, {x: 2, y: 1}), true);766  eq (Z.lte ({x: 2, y: 1}, {x: 1, y: 2}), false);767  eq (Z.lte ({x: 0, y: 0}, {x: 1}), true);768  eq (Z.lte ({x: 0}, {x: 0, y: 0}), true);769  eq (Z.lte ({x: -0}, {x: 0}), true);770  eq (Z.lte ({x: 0}, {x: -0}), true);771  eq (Z.lte ({x: NaN}, {x: NaN}), true);772  eq (Z.lte (Identity (Identity (Identity (0))), Identity (Identity (Identity (0)))), true);773  eq (Z.lte (Identity (Identity (Identity (0))), Identity (Identity (Identity (1)))), true);774  eq (Z.lte (Identity (Identity (Identity (1))), Identity (Identity (Identity (0)))), false);775  eq (Z.lte (Lazy$of (0), Lazy$of (0)), false);776  eq (Z.lte ('abc', 123), false);777  eq (Z.lte (alienValues.Array, domesticValues.Array), true);778  eq (Z.lte (alienValues.Boolean, domesticValues.Boolean), true);779  eq (Z.lte (alienValues.Date, domesticValues.Date), true);780  eq (Z.lte (alienValues.Number, domesticValues.Number), true);781  eq (Z.lte (alienValues.String, domesticValues.String), true);782  const $0 = {z: 0};783  const $1 = {z: 1};784  $0.a = $1;785  $1.a = $0;786  eq (Z.lte ($0, $0), true);787  eq (Z.lte ($0, $1), false);788  eq (Z.lte ($1, $0), false);789});790test ('gt', () => {791  eq (Z.gt.length, 2);792  eq (Z.gt (0, 0), false);793  eq (Z.gt (0, 1), false);794  eq (Z.gt (1, 0), true);795  eq (Z.gt ('abc', 123), false);796});797test ('gte', () => {798  eq (Z.gte.length, 2);799  eq (Z.gte (0, 0), true);800  eq (Z.gte (0, 1), false);801  eq (Z.gte (1, 0), true);802  eq (Z.gte ('abc', 123), false);803});804test ('min', () => {805  eq (Z.min.length, 2);806  eq (Z.min (0, 1), 0);807  eq (Z.min (['x', 'x'], ['x']), ['x']);808});809test ('max', () => {810  eq (Z.max.length, 2);811  eq (Z.max (0, 1), 1);812  eq (Z.max (['x', 'x'], ['x']), ['x', 'x']);813});814test ('clamp', () => {815  eq (Z.clamp.length, 3);816  eq (Z.clamp (0, 100, -1), 0);817  eq (Z.clamp (0, 100, 0), 0);818  eq (Z.clamp (0, 100, 50), 50);819  eq (Z.clamp (0, 100, 100), 100);820  eq (Z.clamp (0, 100, 101), 100);821  eq (Z.clamp ('A', 'Z', '0'), 'A');822  eq (Z.clamp ('A', 'Z', 'A'), 'A');823  eq (Z.clamp ('A', 'Z', 'X'), 'X');824  eq (Z.clamp ('A', 'Z', 'Z'), 'Z');825  eq (Z.clamp ('A', 'Z', '~'), 'Z');826});827test ('compose', () => {828  eq (Z.compose.length, 2);829  eq (Z.compose (Math.sqrt, inc) (99), 10);830  eq (Z.compose (domesticValues.Function, alienValues.Function) (1), 3);831});832test ('id', () => {833  eq (Z.id.length, 1);834  eq (Z.id (Function) (42), 42);835  eq (Z.id (alienValues.Function.constructor) (42), 42);836});837test ('concat', () => {838  eq (Z.concat.length, 2);839  eq (Z.concat ('', ''), '');840  eq (Z.concat ('', 'abc'), 'abc');841  eq (Z.concat ('abc', ''), 'abc');842  eq (Z.concat ('abc', 'def'), 'abcdef');843  eq (Z.concat ([], []), []);844  eq (Z.concat ([], [1, 2, 3]), [1, 2, 3]);845  eq (Z.concat ([1, 2, 3], []), [1, 2, 3]);846  eq (Z.concat ([1, 2, 3], [4, 5, 6]), [1, 2, 3, 4, 5, 6]);847  eq (Z.concat ({}, {}), {});848  eq (Z.concat ({}, {x: 1, y: 2}), {x: 1, y: 2});849  eq (Z.concat ({x: 1, y: 2}, {}), {x: 1, y: 2});850  eq (Z.concat ({x: 1, y: 2}, {y: 3, z: 4}), {x: 1, y: 3, z: 4});851  eq (Z.concat ({x: 1}, Point ()), {x: 1});852  eq (Z.concat (Point (), {x: 1}), {x: 1});853  eq (Z.concat (Point (), Point ()), {});854  eq (Z.concat (Identity (''), Identity ('')), Identity (''));855  eq (Z.concat (Identity (''), Identity ('abc')), Identity ('abc'));856  eq (Z.concat (Identity ('abc'), Identity ('')), Identity ('abc'));857  eq (Z.concat (Identity ('abc'), Identity ('def')), Identity ('abcdef'));858  eq (Z.concat (Nil, Nil), Nil);859  eq (Z.concat (Nil, Cons (1, Cons (2, Cons (3, Nil)))), Cons (1, Cons (2, Cons (3, Nil))));860  eq (Z.concat (Cons (1, Cons (2, Cons (3, Nil))), Nil), Cons (1, Cons (2, Cons (3, Nil))));861  eq (Z.concat (Cons (1, Cons (2, Cons (3, Nil))), Cons (4, Cons (5, Cons (6, Nil)))), Cons (1, Cons (2, Cons (3, Cons (4, Cons (5, Cons (6, Nil)))))));862  eq (Z.concat (alienValues.Array, domesticValues.Array), ['?', '!', '?', '!']);863  eq (Z.concat (alienValues.String, domesticValues.String), '?!?!');864});865test ('empty', () => {866  eq (Z.empty.length, 1);867  eq (Z.empty (String), '');868  eq (Z.empty (Array), []);869  eq (Z.empty (Object), {});870  eq (Z.empty (List), Nil);871  eq (Z.empty (Maybe), Nothing);872  eq (Z.empty (alienValues.String.constructor), '');873  eq (Z.empty (alienValues.Array.constructor), []);874  eq (Z.empty (alienValues.Object.constructor), {});875  assert.throws (876    () => Z.empty (null),877    new TypeError ("Cannot read property 'fantasy-land/empty' of null")878  );879});880test ('invert', () => {881  eq (Z.invert.length, 1);882  eq (Z.invert (Sum (5)), Sum (-5));883  eq (Z.invert (Sum (-5)), Sum (5));884});885test ('filter', () => {886  eq (Z.filter.length, 2);887  eq (Z.filter (odd, []), []);888  eq (Z.filter (odd, [1, 2, 3, 4, 5]), [1, 3, 5]);889  eq (Z.filter (odd, {}), {});890  eq (Z.filter (odd, {x: 1, y: 2, z: 3}), {x: 1, z: 3});891  eq (Z.filter (odd, Nil), Nil);892  eq (Z.filter (odd, Cons (1, Cons (2, Cons (3, Cons (4, Cons (5, Nil)))))), Cons (1, Cons (3, Cons (5, Nil))));893  eq (Z.filter (odd, Nothing), Nothing);894  eq (Z.filter (odd, Just (0)), Nothing);895  eq (Z.filter (odd, Just (1)), Just (1));896});897test ('reject', () => {898  eq (Z.reject.length, 2);899  eq (Z.reject (odd, []), []);900  eq (Z.reject (odd, [1, 2, 3, 4, 5]), [2, 4]);901  eq (Z.reject (odd, {}), {});902  eq (Z.reject (odd, {x: 1, y: 2, z: 3}), {y: 2});903  eq (Z.reject (odd, Nil), Nil);904  eq (Z.reject (odd, Cons (1, Cons (2, Cons (3, Cons (4, Cons (5, Nil)))))), Cons (2, Cons (4, Nil)));905  eq (Z.reject (odd, Nothing), Nothing);906  eq (Z.reject (odd, Just (0)), Just (0));907  eq (Z.reject (odd, Just (1)), Nothing);908});909test ('map', () => {910  eq (Z.map.length, 2);911  eq (Z.map (inc, []), []);912  eq (Z.map (inc, [1, 2, 3]), [2, 3, 4]);913  eq (Z.map (inc, {}), {});914  eq (Z.map (inc, {x: 2, y: 4}), {x: 3, y: 5});915  eq (Z.map (inc, Point ()), {});916  eq (Z.map (inc, length) ('abc'), 4);917  eq (Z.map (inc, Identity (42)), Identity (43));918  eq (Z.map (inc, Nil), Nil);919  eq (Z.map (inc, Cons (1, Cons (2, Cons (3, Nil)))), Cons (2, Cons (3, Cons (4, Nil))));920});921test ('flip', () => {922  eq (Z.flip.length, 2);923  eq (Z.flip (pow, 2) (10), 100);924  eq (Z.flip ([Math.floor, Math.ceil], 1.5), [1, 2]);925  eq (Z.flip ({floor: Math.floor, ceil: Math.ceil}, 1.5), {floor: 1, ceil: 2});926  eq (Z.flip (Cons (Math.floor, Cons (Math.ceil, Nil)), 1.5), Cons (1, Cons (2, Nil)));927});928test ('bimap', () => {929  eq (Z.bimap.length, 3);930  eq (Z.bimap (toUpper, inc, Pair ('abc') (123)), Pair ('ABC') (124));931});932test ('mapLeft', () => {933  eq (Z.mapLeft.length, 2);934  eq (Z.mapLeft (toUpper, Pair ('abc') ('def')), Pair ('ABC') ('def'));935});936test ('promap', () => {937  eq (Z.promap.length, 3);938  const lengths = xs => Z.map (length, xs);939  eq (Z.promap (lengths, square, sum) (['foo', 'bar', 'baz', 'quux']), 169);940});941test ('ap', () => {942  eq (Z.ap.length, 2);943  eq (Z.ap ([], []), []);944  eq (Z.ap ([], [1, 2, 3]), []);945  eq (Z.ap ([inc], []), []);946  eq (Z.ap ([inc], [1, 2, 3]), [2, 3, 4]);947  eq (Z.ap ([inc, square], [1, 2, 3]), [2, 3, 4, 1, 4, 9]);948  eq (Z.ap ({}, {}), {});949  eq (Z.ap ({}, {x: 1, y: 2, z: 3}), {});950  eq (Z.ap ({x: inc}, {}), {});951  eq (Z.ap ({x: inc}, {x: 1}), {x: 2});952  eq (Z.ap ({x: inc, y: square}, {x: 1, y: 2}), {x: 2, y: 4});953  eq (Z.ap ({x: inc, y: square, z: abs}, {w: 4, x: 1, y: 2}), {x: 2, y: 4});954  eq (Z.ap ({}, {toString: 42}), {});955  eq (Z.ap ({x: inc, y: inc}, Point ()), {});956  eq (Z.ap (pow, abs) (-1), pow (-1) (abs (-1)));957  eq (Z.ap (pow, abs) (-2), pow (-2) (abs (-2)));958  eq (Z.ap (pow, abs) (-3), pow (-3) (abs (-3)));959  eq (Z.ap (Identity (inc), Identity (42)), Identity (43));960  eq (Z.ap (Nil, Nil), Nil);961  eq (Z.ap (Nil, Cons (1, Cons (2, Cons (3, Nil)))), Nil);962  eq (Z.ap (Cons (inc, Nil), Nil), Nil);963  eq (Z.ap (Cons (inc, Nil), Cons (1, Cons (2, Cons (3, Nil)))), Cons (2, Cons (3, Cons (4, Nil))));964  eq (Z.ap (Cons (inc, Cons (square, Nil)), Cons (1, Cons (2, Cons (3, Nil)))), Cons (2, Cons (3, Cons (4, Cons (1, Cons (4, Cons (9, Nil)))))));965});966test ('lift2', () => {967  eq (Z.lift2.length, 3);968  eq (Z.lift2 (pow, [10], [1, 2, 3]), [10, 100, 1000]);969  eq (Z.lift2 (pow, Identity (10), Identity (3)), Identity (1000));970});971test ('lift3', () => {972  eq (Z.lift3.length, 4);973  eq (Z.lift3 (wrap, ['<'], ['>'], ['foo', 'bar', 'baz']), ['<foo>', '<bar>', '<baz>']);974  eq (Z.lift3 (wrap, Identity ('<'), Identity ('>'), Identity ('baz')), Identity ('<baz>'));975});976test ('apFirst', () => {977  eq (Z.apFirst.length, 2);978  eq (Z.apFirst ([1, 2], [3, 4]), [1, 1, 2, 2]);979  eq (Z.apFirst (Identity (1), Identity (2)), Identity (1));980});981test ('apSecond', () => {982  eq (Z.apSecond.length, 2);983  eq (Z.apSecond ([1, 2], [3, 4]), [3, 4, 3, 4]);984  eq (Z.apSecond (Identity (1), Identity (2)), Identity (2));985});986test ('of', () => {987  eq (Z.of.length, 2);988  eq (Z.of (Array, 42), [42]);989  eq (Z.of (Function, 42) (null), 42);990  eq (Z.of (Identity, 42), Identity (42));991  eq (Z.of (List, 42), Cons (42, Nil));992  eq (Z.of (Maybe, 42), Just (42));993});994test ('append', () => {995  eq (Z.append.length, 2);996  eq (Z.append (3, []), [3]);997  eq (Z.append (3, [1, 2]), [1, 2, 3]);998  eq (Z.append (3, Nil), Cons (3, Nil));999  eq (Z.append (3, Cons (1, Cons (2, Nil))), Cons (1, Cons (2, Cons (3, Nil))));1000  eq (Z.append ([5, 6], [[1, 2], [3, 4]]), [[1, 2], [3, 4], [5, 6]]);1001  eq (Z.append ([2], Nothing), Just ([2]));1002  eq (Z.append ([2], Just ([1])), Just ([1, 2]));1003});1004test ('prepend', () => {1005  eq (Z.prepend.length, 2);1006  eq (Z.prepend (1, []), [1]);1007  eq (Z.prepend (1, [2, 3]), [1, 2, 3]);1008  eq (Z.prepend (1, Nil), Cons (1, Nil));1009  eq (Z.prepend (1, Cons (2, Cons (3, Nil))), Cons (1, Cons (2, Cons (3, Nil))));1010  eq (Z.prepend ([1, 2], [[3, 4], [5, 6]]), [[1, 2], [3, 4], [5, 6]]);1011  eq (Z.prepend ([1], Nothing), Just ([1]));1012  eq (Z.prepend ([1], Just ([2])), Just ([1, 2]));1013});1014test ('chain', () => {1015  eq (Z.chain.length, 2);1016  eq (Z.chain (double, []), []);1017  eq (Z.chain (double, [1, 2, 3]), [1, 1, 2, 2, 3, 3]);1018  eq (Z.chain (identity, [[1, 2], [3, 4], [5, 6]]), [1, 2, 3, 4, 5, 6]);1019  eq (Z.chain (repeat, abs) (-1), [-1]);1020  eq (Z.chain (repeat, abs) (-2), [-2, -2]);1021  eq (Z.chain (repeat, abs) (-3), [-3, -3, -3]);1022  eq (Z.chain (identInc, Identity (42)), Identity (43));1023  eq (Z.chain (identity, Identity (Identity (0))), Identity (0));1024  eq ((Z.chain (identity, [((new Array (1e6)).join ('x')).split ('')])).length, 999999);1025});1026test ('join', () => {1027  eq (Z.join.length, 1);1028  eq (Z.join ([]), []);1029  eq (Z.join ([[]]), []);1030  eq (Z.join ([[[]]]), [[]]);1031  eq (Z.join ([[1], [2], [3]]), [1, 2, 3]);1032  eq (Z.join ([[[1, 2, 3]]]), [[1, 2, 3]]);1033  eq (Z.join (Identity (Identity (1))), Identity (1));1034  eq (Z.join (Identity (Identity (Identity (1)))), Identity (Identity (1)));1035});1036test ('chainRec', () => {1037  eq (Z.chainRec.length, 3);1038  let count = 0;1039  //  squash :: (Any -> a, Any -> a, Any) -> Array b1040  const squash = (next, done, x) => {1041    if (Array.isArray (x)) return x.map (next);1042    count += 1;1043    return [done (x)];1044  };1045  eq (Z.chainRec (Array, squash, [1, [[2, 3], 4], 5]), [1, 2, 3, 4, 5]);1046  eq (count, 5);1047  eq (Z.chainRec (Array, (next, done, n) => n === 0 ? [done ('DONE')] : [next (n - 1)], 100000), ['DONE']);1048  const stepper = (next, done, n) => (1049    n === 300001050    ? Z.map (done, env => n + env.inc)1051    : Z.map (next, env => n + env.step)1052  );1053  eq (Z.chainRec (Function, stepper, 0) ({step: 2, inc: 100}), 30100);1054  eq (Z.chainRec (Array, (next, done, n) => n === 0 ? [done (0)] : Z.map (next, repeat (n) (0)), 1e6).length, 1e6);1055});1056test ('alt', () => {1057  eq (Z.alt.length, 2);1058  eq (Z.alt ([], []), []);1059  eq (Z.alt ([], [1, 2, 3]), [1, 2, 3]);1060  eq (Z.alt ([1, 2, 3], []), [1, 2, 3]);1061  eq (Z.alt ([1, 2, 3], [4, 5, 6]), [1, 2, 3, 4, 5, 6]);1062  eq (Z.alt ({}, {}), {});1063  eq (Z.alt ({}, {a: 1, b: 2, c: 3}), {a: 1, b: 2, c: 3});1064  eq (Z.alt ({a: 1, b: 2, c: 3}, {}), {a: 1, b: 2, c: 3});1065  eq (Z.alt ({a: 1, b: 2, c: 3}, {d: 4, e: 5, f: 6}), {a: 1, b: 2, c: 3, d: 4, e: 5, f: 6});1066  eq (Z.alt ({a: 1}, Point ()), {a: 1});1067  eq (Z.alt (Point (), {a: 1}), {a: 1});1068  eq (Z.alt (Point (), Point ()), {});1069  eq (Z.alt (Nothing, Nothing), Nothing);1070  eq (Z.alt (Nothing, Just (1)), Just (1));1071  eq (Z.alt (Just (2), Nothing), Just (2));1072  eq (Z.alt (Just (3), Just (4)), Just (3));1073});1074test ('zero', () => {1075  eq (Z.zero.length, 1);1076  eq (Z.zero (Array), []);1077  eq (Z.zero (Object), {});1078  eq (Z.zero (Maybe), Nothing);1079});1080const testReduce = reduce => {1081  eq (reduce (Z.concat, 'x', []), 'x');1082  eq (reduce (Z.concat, 'x', ['a', 'b', 'c']), 'xabc');1083  eq (reduce (add, 0, {}), 0);1084  eq (reduce (add, 0, {a: 1, b: 2, c: 3, d: 4, e: 5}), 15);1085  eq (reduce ((xs, x) => Z.concat (xs, [x]), [], {a: 1, b: 2, c: 3}), [1, 2, 3]);1086  eq (reduce ((xs, x) => Z.concat (xs, [x]), [], {c: 3, b: 2, a: 1}), [1, 2, 3]);1087  eq (reduce (Z.concat, 'x', Nil), 'x');1088  eq (reduce (Z.concat, 'x', Cons ('a', Cons ('b', Cons ('c', Nil)))), 'xabc');1089};1090test ('reduce', () => {1091  eq (Z.reduce.length, 3);1092  testReduce (Z.reduce);1093});1094test ('size', () => {1095  eq (Z.size.length, 1);1096  eq (Z.size ([]), 0);1097  eq (Z.size (['foo']), 1);1098  eq (Z.size (['foo', 'bar']), 2);1099  eq (Z.size (['foo', 'bar', 'baz']), 3);1100  eq (Z.size (Nil), 0);1101  eq (Z.size (Cons ('foo', Nil)), 1);1102  eq (Z.size (Cons ('foo', Cons ('bar', Nil))), 2);1103  eq (Z.size (Cons ('foo', Cons ('bar', Cons ('baz', Nil)))), 3);1104  eq (Z.size (Identity ('quux')), 1);1105  eq (Z.size (Nothing), 0);1106  eq (Z.size (Just (0)), 1);1107  eq (Z.size (Pair ('abc') (123)), 1);1108});1109test ('all', () => {1110  eq (Z.all.length, 2);1111  eq (Z.all (gt (0), []), true);1112  eq (Z.all (gt (0), [0]), false);1113  eq (Z.all (gt (0), [1]), true);1114  eq (Z.all (gt (0), [0, 0]), false);1115  eq (Z.all (gt (0), [0, 1]), false);1116  eq (Z.all (gt (0), [1, 0]), false);1117  eq (Z.all (gt (0), [1, 1]), true);1118  eq (Z.all (gt (0), Nil), true);1119  eq (Z.all (gt (0), Cons (0, Nil)), false);1120  eq (Z.all (gt (0), Cons (1, Nil)), true);1121  eq (Z.all (gt (0), Cons (0, Cons (0, Nil))), false);1122  eq (Z.all (gt (0), Cons (0, Cons (1, Nil))), false);1123  eq (Z.all (gt (0), Cons (1, Cons (0, Nil))), false);1124  eq (Z.all (gt (0), Cons (1, Cons (1, Nil))), true);1125  eq (Z.all (gt (0), Nothing), true);1126  eq (Z.all (gt (0), Just (0)), false);1127  eq (Z.all (gt (0), Just (1)), true);1128});1129test ('any', () => {1130  eq (Z.any.length, 2);1131  eq (Z.any (gt (0), []), false);1132  eq (Z.any (gt (0), [0]), false);1133  eq (Z.any (gt (0), [1]), true);1134  eq (Z.any (gt (0), [0, 0]), false);1135  eq (Z.any (gt (0), [0, 1]), true);1136  eq (Z.any (gt (0), [1, 0]), true);1137  eq (Z.any (gt (0), [1, 1]), true);1138  eq (Z.any (gt (0), Nil), false);1139  eq (Z.any (gt (0), Cons (0, Nil)), false);1140  eq (Z.any (gt (0), Cons (1, Nil)), true);1141  eq (Z.any (gt (0), Cons (0, Cons (0, Nil))), false);1142  eq (Z.any (gt (0), Cons (0, Cons (1, Nil))), true);1143  eq (Z.any (gt (0), Cons (1, Cons (0, Nil))), true);1144  eq (Z.any (gt (0), Cons (1, Cons (1, Nil))), true);1145  eq (Z.any (gt (0), Nothing), false);1146  eq (Z.any (gt (0), Just (0)), false);1147  eq (Z.any (gt (0), Just (1)), true);1148});1149test ('none', () => {1150  eq (Z.none.length, 2);1151  eq (Z.none (gt (0), []), true);1152  eq (Z.none (gt (0), [0]), true);1153  eq (Z.none (gt (0), [1]), false);1154  eq (Z.none (gt (0), [0, 0]), true);1155  eq (Z.none (gt (0), [0, 1]), false);1156  eq (Z.none (gt (0), [1, 0]), false);1157  eq (Z.none (gt (0), [1, 1]), false);1158  eq (Z.none (gt (0), Nil), true);1159  eq (Z.none (gt (0), Cons (0, Nil)), true);1160  eq (Z.none (gt (0), Cons (1, Nil)), false);1161  eq (Z.none (gt (0), Cons (0, Cons (0, Nil))), true);1162  eq (Z.none (gt (0), Cons (0, Cons (1, Nil))), false);1163  eq (Z.none (gt (0), Cons (1, Cons (0, Nil))), false);1164  eq (Z.none (gt (0), Cons (1, Cons (1, Nil))), false);1165  eq (Z.none (gt (0), Nothing), true);1166  eq (Z.none (gt (0), Just (0)), true);1167  eq (Z.none (gt (0), Just (1)), false);1168});1169test ('elem', () => {1170  eq (Z.elem.length, 2);1171  eq (Z.elem ('a', ['a', 'b', 'c']), true);1172  eq (Z.elem ('b', ['a', 'b', 'c']), true);1173  eq (Z.elem ('c', ['a', 'b', 'c']), true);1174  eq (Z.elem ('d', ['a', 'b', 'c']), false);1175  eq (Z.elem (1, {x: 1, y: 2, z: 3}), true);1176  eq (Z.elem (2, {x: 1, y: 2, z: 3}), true);1177  eq (Z.elem (3, {x: 1, y: 2, z: 3}), true);1178  eq (Z.elem (4, {x: 1, y: 2, z: 3}), false);1179  eq (Z.elem (0, Just (0)), true);1180  eq (Z.elem (0, Just (1)), false);1181  eq (Z.elem (0, Nothing), false);1182});1183test ('intercalate', () => {1184  eq (Z.intercalate.length, 2);1185  eq (Z.intercalate (', ', []), '');1186  eq (Z.intercalate (', ', ['foo']), 'foo');1187  eq (Z.intercalate (', ', ['foo', 'bar']), 'foo, bar');1188  eq (Z.intercalate (', ', ['foo', 'bar', 'baz']), 'foo, bar, baz');1189  eq (Z.intercalate ([0, 0, 0], []), []);1190  eq (Z.intercalate ([0, 0, 0], [[1]]), [1]);1191  eq (Z.intercalate ([0, 0, 0], [[1], [2]]), [1, 0, 0, 0, 2]);1192  eq (Z.intercalate ([0, 0, 0], [[1], [2], [3]]), [1, 0, 0, 0, 2, 0, 0, 0, 3]);1193  eq (Z.intercalate ('.', Nil), '');1194  eq (Z.intercalate ('.', Cons ('x', Nil)), 'x');1195  eq (Z.intercalate ('.', Cons ('x', Cons ('y', Nil))), 'x.y');1196  eq (Z.intercalate ('.', Cons ('x', Cons ('y', Cons ('z', Nil)))), 'x.y.z');1197});1198test ('foldMap', () => {1199  eq (Z.foldMap.length, 3);1200  // Monoid instance for functions of type a -> a corresponding1201  // to reverse function composition1202  function DualEndo(f) {1203    if (!(this instanceof DualEndo)) return new DualEndo (f);1204    this.runEndo = f;1205  }1206  DualEndo['fantasy-land/empty'] = () => DualEndo (identity);1207  DualEndo.prototype['fantasy-land/concat'] = function(other) {1208    return DualEndo (a => other.runEndo (this.runEndo (a)));1209  };1210  // Derive reduce (foldl) from foldMap1211  const reduce = (f, z, x) => {1212    const mmap = a => DualEndo (b => f (b, a));1213    const finalEndo = Z.foldMap (DualEndo, mmap, x);1214    return finalEndo.runEndo (z);1215  };1216  // Test derived reduce behaves identically to Z.reduce1217  testReduce (reduce);1218});1219test ('reverse', () => {1220  eq (Z.reverse.length, 1);1221  eq (Z.reverse ([]), []);1222  eq (Z.reverse ([1]), [1]);1223  eq (Z.reverse ([1, 2]), [2, 1]);1224  eq (Z.reverse ([1, 2, 3]), [3, 2, 1]);1225  eq (Z.reverse (Nil), Nil);1226  eq (Z.reverse (Cons (1, Nil)), Cons (1, Nil));1227  eq (Z.reverse (Cons (1, Cons (2, Nil))), Cons (2, Cons (1, Nil)));1228  eq (Z.reverse (Cons (1, Cons (2, Cons (3, Nil)))), Cons (3, Cons (2, Cons (1, Nil))));1229});1230test ('sort', () => {1231  eq (Z.sort.length, 1);1232  const runAssertions = () => {1233    eq (Z.sort ([]), []);1234    eq (Z.sort (['foo']), ['foo']);1235    eq (Z.sort (['foo', 'bar']), ['bar', 'foo']);1236    eq (Z.sort (['foo', 'bar', 'baz']), ['bar', 'baz', 'foo']);1237    eq (Z.sort (Nil), Nil);1238    eq (Z.sort (Cons ('foo', Nil)), Cons ('foo', Nil));1239    eq (Z.sort (Cons ('foo', Cons ('bar', Nil))), Cons ('bar', Cons ('foo', Nil)));1240    eq (Z.sort (Cons ('foo', Cons ('bar', Cons ('baz', Nil)))), Cons ('bar', Cons ('baz', Cons ('foo', Nil))));1241    eq (Z.sort ([NaN, 3, NaN, 1, NaN, 2, NaN]), [NaN, NaN, NaN, NaN, 1, 2, 3]);1242    eq (Z.sort ([Just (3), Just (1), Just (2)]), [Just (1), Just (2), Just (3)]);1243  };1244  runAssertions ();1245  withUnstableArraySort (runAssertions);1246});1247test ('sortBy', () => {1248  eq (Z.sortBy.length, 2);1249  const rank = card => card.rank;1250  const suit = card => card.suit;1251  const _7s = {rank: 7, suit: 's'};1252  const _5h = {rank: 5, suit: 'h'};1253  const _2h = {rank: 2, suit: 'h'};1254  const _5s = {rank: 5, suit: 's'};1255  const runAssertions = () => {1256    eq (Z.sortBy (rank, [_7s, _5h, _2h, _5s]), [_2h, _5h, _5s, _7s]);1257    eq (Z.sortBy (rank, [_7s, _5s, _2h, _5h]), [_2h, _5s, _5h, _7s]);1258    eq (Z.sortBy (suit, [_7s, _5h, _2h, _5s]), [_5h, _2h, _7s, _5s]);1259    eq (Z.sortBy (suit, [_5s, _2h, _5h, _7s]), [_2h, _5h, _5s, _7s]);1260  };1261  runAssertions ();1262  withUnstableArraySort (runAssertions);1263});1264test ('traverse', () => {1265  eq (Z.traverse.length, 3);1266  eq (Z.traverse (Array, identity, []), [[]]);1267  eq (Z.traverse (Array, identity, [[1], [2], [3]]), [[1, 2, 3]]);1268  eq (Z.traverse (Array, identity, [[1, 2, 3], [4, 5]]), [[1, 4], [1, 5], [2, 4], [2, 5], [3, 4], [3, 5]]);1269  eq ((Z.traverse (Array, identity, repeat (6) (range (10)))).length, 1e6);1270  eq (Z.traverse (Maybe, parseInt_ (16), {a: 'A', b: 'B', c: 'C'}), Just ({a: 10, b: 11, c: 12}));1271  eq (Z.traverse (Maybe, parseInt_ (16), {a: 'A', b: 'B', c: 'C', x: 'X'}), Nothing);1272  eq (Z.traverse (Identity, identInc, []), Identity ([]));1273  eq (Z.traverse (Identity, identInc, [1, 2, 3]), Identity ([2, 3, 4]));1274  eq (Z.traverse (Identity, identInc, Nil), Identity (Nil));1275  eq (Z.traverse (Identity, identInc, Cons (1, Cons (2, Cons (3, Nil)))), Identity (Cons (2, Cons (3, Cons (4, Nil)))));1276  eq (((Z.traverse (Lazy, Lazy$of, range (70000))).run ()).length, 70000);1277  eq (Z.traverse (Array, identity, {a: [1, 2], b: [3, 4]}), [{a: 1, b: 3}, {a: 1, b: 4}, {a: 2, b: 3}, {a: 2, b: 4}]);1278});1279test ('sequence', () => {1280  eq (Z.sequence.length, 2);1281  eq (Z.sequence (Identity, []), Identity ([]));1282  eq (Z.sequence (Identity, [Identity (1), Identity (2), Identity (3)]), Identity ([1, 2, 3]));1283  eq (Z.sequence (Array, Identity ([])), []);1284  eq (Z.sequence (Array, Identity ([1, 2, 3])), [Identity (1), Identity (2), Identity (3)]);1285  eq (Z.sequence (Identity, Nil), Identity (Nil));1286  eq (Z.sequence (Identity, Cons (Identity (1), Cons (Identity (2), Cons (Identity (3), Nil)))), Identity (Cons (1, Cons (2, Cons (3, Nil)))));1287  eq (Z.sequence (List, Identity (Nil)), Nil);1288  eq (Z.sequence (List, Identity (Cons (1, Cons (2, Cons (3, Nil))))), Cons (Identity (1), Cons (Identity (2), Cons (Identity (3), Nil))));1289  eq (Z.sequence (Maybe, {a: Just ('A'), b: Just ('B'), c: Just ('C')}), Just ({a: 'A', b: 'B', c: 'C'}));1290  eq (Z.sequence (Maybe, {a: Just ('A'), b: Just ('B'), c: Just ('C'), x: Nothing}), Nothing);1291  eq (Z.sequence (Array, {a: [1, 2], b: [3, 4]}), [{a: 1, b: 3}, {a: 1, b: 4}, {a: 2, b: 3}, {a: 2, b: 4}]);1292});1293test ('extend', () => {1294  eq (Z.extend.length, 2);1295  eq (Z.extend (joinWith (''), []), []);1296  eq (Z.extend (joinWith (''), ['x']), ['x']);1297  eq (Z.extend (joinWith (''), ['x', 'y']), ['xy', 'y']);1298  eq (Z.extend (joinWith (''), ['x', 'y', 'z']), ['xyz', 'yz', 'z']);1299  eq (Z.extend (id => Z.reduce (add, 1, id), Identity (42)), Identity (43));1300  eq (Z.extend (f => f ([3, 4]), Z.reverse) ([1, 2]), [4, 3, 2, 1]);1301});1302test ('duplicate', () => {1303  eq (Z.duplicate.length, 1);1304  eq (Z.duplicate ([]), []);1305  eq (Z.duplicate ([[]]), [[[]]]);1306  eq (Z.duplicate ([1, 2, 3]), [[1, 2, 3], [2, 3], [3]]);1307  eq (Z.duplicate ([[1, 2, 3]]), [[[1, 2, 3]]]);1308  eq (Z.duplicate (Identity (1)), Identity (Identity (1)));1309  eq (Z.duplicate (Identity (Identity (1))), Identity (Identity (Identity (1))));1310});1311test ('extract', () => {1312  eq (Z.extract.length, 1);1313  eq (Z.extract (Identity (42)), 42);1314});1315test ('contramap', () => {1316  eq (Z.contramap.length, 2);1317  eq (Z.contramap (length, inc) ('abc'), 4);1318});1319const testLaws = specs => {1320  (Object.keys (specs)).forEach (typeClassName => {1321    suite (typeClassName, () => {1322      const spec = specs[typeClassName];1323      (Object.keys (spec.module)).forEach (name => {1324        test (name.replace (/[A-Z]/g, c => ' ' + c.toLowerCase ()),1325              spec.module[name] (...spec.laws[name]));1326      });1327    });1328  });1329};1330suite ('laws', () => {1331  suite ('Null', () => {1332    testLaws ({1333      Setoid: {1334        module: laws.Setoid,1335        laws: {1336          reflexivity: [1337            jsc.constant (null),1338          ],1339          symmetry: [1340            jsc.constant (null),1341            jsc.constant (null),1342          ],1343          transitivity: [1344            jsc.constant (null),1345            jsc.constant (null),1346            jsc.constant (null),1347          ],1348        },1349      },1350      Ord: {1351        module: laws.Ord,1352        laws: {1353          totality: [1354            jsc.constant (null),1355            jsc.constant (null),1356          ],1357          antisymmetry: [1358            jsc.constant (null),1359            jsc.constant (null),1360            jsc.constant (null),1361          ],1362          transitivity: [1363            jsc.constant (null),1364            jsc.constant (null),1365            jsc.constant (null),1366          ],1367        },1368      },1369    });1370  });1371  suite ('Undefined', () => {1372    testLaws ({1373      Setoid: {1374        module: laws.Setoid,1375        laws: {1376          reflexivity: [1377            jsc.constant (undefined),1378          ],1379          symmetry: [1380            jsc.constant (undefined),1381            jsc.constant (undefined),1382          ],1383          transitivity: [1384            jsc.constant (undefined),1385            jsc.constant (undefined),1386            jsc.constant (undefined),1387          ],1388        },1389      },1390      Ord: {1391        module: laws.Ord,1392        laws: {1393          totality: [1394            jsc.constant (undefined),1395            jsc.constant (undefined),1396          ],1397          antisymmetry: [1398            jsc.constant (undefined),1399            jsc.constant (undefined),1400            jsc.constant (undefined),1401          ],1402          transitivity: [1403            jsc.constant (undefined),1404            jsc.constant (undefined),1405            jsc.constant (undefined),1406          ],1407        },1408      },1409    });1410  });1411  suite ('Boolean', () => {1412    testLaws ({1413      Setoid: {1414        module: laws.Setoid,1415        laws: {1416          reflexivity: [1417            jsc.bool,1418          ],1419          symmetry: [1420            jsc.bool,1421            jsc.bool,1422          ],1423          transitivity: [1424            jsc.bool,1425            jsc.bool,1426            jsc.bool,1427          ],1428        },1429      },1430      Ord: {1431        module: laws.Ord,1432        laws: {1433          totality: [1434            jsc.bool,1435            jsc.bool,1436          ],1437          antisymmetry: [1438            jsc.bool,1439            jsc.bool,1440            jsc.bool,1441          ],1442          transitivity: [1443            jsc.bool,1444            jsc.bool,1445            jsc.bool,1446          ],1447        },1448      },1449    });1450  });1451  suite ('Number', () => {1452    const arb = jsc.oneof (jsc.number, jsc.number, jsc.number, jsc.constant (Infinity), jsc.constant (-Infinity), jsc.constant (NaN));1453    testLaws ({1454      Setoid: {1455        module: laws.Setoid,1456        laws: {1457          reflexivity: [1458            arb,1459          ],1460          symmetry: [1461            arb,1462            arb,1463          ],1464          transitivity: [1465            arb,1466            arb,1467            arb,1468          ],1469        },1470      },1471      Ord: {1472        module: laws.Ord,1473        laws: {1474          totality: [1475            arb,1476            arb,1477          ],1478          antisymmetry: [1479            arb,1480            arb,1481          ],1482          transitivity: [1483            arb,1484            arb,1485            arb,1486          ],1487        },1488      },1489    });1490  });1491  suite ('Date', () => {1492    const arb = jsc.oneof (jsc.datetime, jsc.datetime, jsc.constant (new Date (NaN)));1493    testLaws ({1494      Setoid: {1495        module: laws.Setoid,1496        laws: {1497          reflexivity: [1498            arb,1499          ],1500          symmetry: [1501            arb,1502            arb,1503          ],1504          transitivity: [1505            arb,1506            arb,1507            arb,1508          ],1509        },1510      },1511      Ord: {1512        module: laws.Ord,1513        laws: {1514          totality: [1515            arb,1516            arb,1517          ],1518          antisymmetry: [1519            arb,1520            arb,1521          ],1522          transitivity: [1523            arb,1524            arb,1525            arb,1526          ],1527        },1528      },1529    });1530  });1531  suite ('RegExp', () => {1532    const flagsArb = jsc.oneof (['', 'g', 'i', 'm', 'gi', 'gm', 'im', 'gim'].map (jsc.constant));1533    const patternArb = jsc.suchthat (jsc.string, s => {1534      try {1535        new RegExp (s);1536        return true;1537      } catch (e) {1538        return false;1539      }1540    });1541    const arb = mapArb (({flags, pattern}) => new RegExp (pattern, flags))1542                       (jsc.record ({flags: flagsArb, pattern: patternArb}));1543    testLaws ({1544      Setoid: {1545        module: laws.Setoid,1546        laws: {1547          reflexivity: [1548            arb,1549          ],1550          symmetry: [1551            arb,1552            arb,1553          ],1554          transitivity: [1555            arb,1556            arb,1557            arb,1558          ],1559        },1560      },1561    });1562  });1563  suite ('String', () => {1564    testLaws ({1565      Setoid: {1566        module: laws.Setoid,1567        laws: {1568          reflexivity: [1569            jsc.string,1570          ],1571          symmetry: [1572            jsc.string,1573            jsc.string,1574          ],1575          transitivity: [1576            jsc.string,1577            jsc.string,1578            jsc.string,1579          ],1580        },1581      },1582      Ord: {1583        module: laws.Ord,1584        laws: {1585          totality: [1586            jsc.string,1587            jsc.string,1588          ],1589          antisymmetry: [1590            jsc.string,1591            jsc.string,1592          ],1593          transitivity: [1594            jsc.string,1595            jsc.string,1596            jsc.string,1597          ],1598        },1599      },1600      Semigroup: {1601        module: laws.Semigroup (Z.equals),1602        laws: {1603          associativity: [1604            jsc.string,1605            jsc.string,1606            jsc.string,1607          ],1608        },1609      },1610      Monoid: {1611        module: laws.Monoid (Z.equals, String),1612        laws: {1613          leftIdentity: [1614            jsc.string,1615          ],1616          rightIdentity: [1617            jsc.string,1618          ],1619        },1620      },1621    });1622  });1623  suite ('Array', () => {1624    testLaws ({1625      Setoid: {1626        module: laws.Setoid,1627        laws: {1628          reflexivity: [1629            jsc.array (jsc.number),1630          ],1631          symmetry: [1632            jsc.array (jsc.number),1633            jsc.array (jsc.number),1634          ],1635          transitivity: [1636            jsc.array (jsc.number),1637            jsc.array (jsc.number),1638            jsc.array (jsc.number),1639          ],1640        },1641      },1642      Ord: {1643        module: laws.Ord,1644        laws: {1645          totality: [1646            jsc.array (jsc.number),1647            jsc.array (jsc.number),1648          ],1649          antisymmetry: [1650            jsc.array (jsc.number),1651            jsc.array (jsc.number),1652          ],1653          transitivity: [1654            jsc.array (jsc.number),1655            jsc.array (jsc.number),1656            jsc.array (jsc.number),1657          ],1658        },1659      },1660      Semigroup: {1661        module: laws.Semigroup (Z.equals),1662        laws: {1663          associativity: [1664            jsc.array (jsc.number),1665            jsc.array (jsc.number),1666            jsc.array (jsc.number),1667          ],1668        },1669      },1670      Monoid: {1671        module: laws.Monoid (Z.equals, Array),1672        laws: {1673          leftIdentity: [1674            jsc.array (jsc.number),1675          ],1676          rightIdentity: [1677            jsc.array (jsc.number),1678          ],1679        },1680      },1681      Filterable: {1682        module: laws.Filterable (Z.equals),1683        laws: {1684          distributivity: [1685            jsc.array (jsc.number),1686            jsc.constant (gt (-10)),1687            jsc.constant (lt (10)),1688          ],1689          identity: [1690            jsc.array (jsc.number),1691          ],1692          annihilation: [1693            jsc.array (jsc.number),1694            jsc.array (jsc.number),1695          ],1696        },1697      },1698      Functor: {1699        module: laws.Functor (Z.equals),1700        laws: {1701          identity: [1702            jsc.array (jsc.number),1703          ],1704          composition: [1705            jsc.array (jsc.number),1706            jsc.constant (Math.sqrt),1707            jsc.constant (Math.abs),1708          ],1709        },1710      },1711      Apply: {1712        module: laws.Apply (Z.equals),1713        laws: {1714          composition: [1715            jsc.constant ([Math.sqrt, square]),1716            jsc.constant ([Math.abs]),1717            jsc.array (jsc.number),1718          ],1719        },1720      },1721      Applicative: {1722        module: laws.Applicative (Z.equals, Array),1723        laws: {1724          identity: [1725            jsc.array (jsc.number),1726          ],1727          homomorphism: [1728            jsc.constant (square),1729            jsc.number,1730          ],1731          interchange: [1732            jsc.constant ([Math.abs, square]),1733            jsc.number,1734          ],1735        },1736      },1737      Chain: {1738        module: laws.Chain (Z.equals),1739        laws: {1740          associativity: [1741            jsc.array (jsc.number),1742            jsc.constant (x => x > 0 ? [x] : []),1743            jsc.constant (x => [-x, x]),1744          ],1745        },1746      },1747      ChainRec: {1748        module: laws.ChainRec (Z.equals, Array),1749        laws: {1750          equivalence: [1751            jsc.constant (s => s.length === 2),1752            jsc.constant (s => [s + 'o', s + 'n']),1753            jsc.constant (s => [s + '!', s + '?']),1754            jsc.constant (''),1755          ],1756        },1757      },1758      Monad: {1759        module: laws.Monad (Z.equals, Array),1760        laws: {1761          leftIdentity: [1762            jsc.constant (double),1763            jsc.number,1764          ],1765          rightIdentity: [1766            jsc.array (jsc.number),1767          ],1768        },1769      },1770      Alt: {1771        module: laws.Alt (Z.equals),1772        laws: {1773          associativity: [1774            jsc.array (jsc.number),1775            jsc.array (jsc.number),1776            jsc.array (jsc.number),1777          ],1778          distributivity: [1779            jsc.array (jsc.number),1780            jsc.array (jsc.number),1781            jsc.constant (square),1782          ],1783        },1784      },1785      Plus: {1786        module: laws.Plus (Z.equals, Array),1787        laws: {1788          leftIdentity: [1789            jsc.array (jsc.number),1790          ],1791          rightIdentity: [1792            jsc.array (jsc.number),1793          ],1794          annihilation: [1795            jsc.constant (square),1796          ],1797        },1798      },1799      Alternative: {1800        module: laws.Alternative (Z.equals, Array),1801        laws: {1802          distributivity: [1803            jsc.array (jsc.number),1804            jsc.constant ([Math.abs, Math.sqrt]),1805            jsc.constant ([square]),1806          ],1807          annihilation: [1808            jsc.array (jsc.number),1809          ],1810        },1811      },1812      Foldable: {1813        module: laws.Foldable (Z.equals),1814        laws: {1815          associativity: [1816            jsc.constant ((x, y) => x - y),1817            jsc.number,1818            jsc.array (jsc.number),1819          ],1820        },1821      },1822      Traversable: {1823        module: laws.Traversable (Z.equals),1824        laws: {1825          naturality: [1826            jsc.constant (List),1827            jsc.constant (Array),1828            jsc.constant (listToArray),1829            jsc.array (ListArb (jsc.number)),1830          ],1831          identity: [1832            jsc.constant (Identity),1833            jsc.array (jsc.number),1834          ],1835          composition: [1836            jsc.constant (Maybe),1837            jsc.constant (List),1838            jsc.array (MaybeArb (ListArb (jsc.number))),1839          ],1840        },1841      },1842      Extend: {1843        module: laws.Extend (Z.equals),1844        laws: {1845          associativity: [1846            jsc.array (jsc.number),1847            jsc.constant (product),1848            jsc.constant (sum),1849          ],1850        },1851      },1852    });1853  });1854  suite ('Arguments', () => {1855    const arb = mapArb (Function.prototype.apply.bind (args))1856                       (jsc.array (jsc.oneof (jsc.number, jsc.string)));1857    testLaws ({1858      Setoid: {1859        module: laws.Setoid,1860        laws: {1861          reflexivity: [1862            arb,1863          ],1864          symmetry: [1865            arb,1866            arb,1867          ],1868          transitivity: [1869            arb,1870            arb,1871            arb,1872          ],1873        },1874      },1875      Ord: {1876        module: laws.Ord,1877        laws: {1878          totality: [1879            arb,1880            arb,1881          ],1882          antisymmetry: [1883            arb,1884            arb,1885          ],1886          transitivity: [1887            arb,1888            arb,1889            arb,1890          ],1891        },1892      },1893    });1894  });1895  suite ('Error', () => {1896    const arb = smapArb (s => new Error (s)) (e => e.message) (jsc.string);1897    testLaws ({1898      Setoid: {1899        module: laws.Setoid,1900        laws: {1901          reflexivity: [1902            arb,1903          ],1904          symmetry: [1905            arb,1906            arb,1907          ],1908          transitivity: [1909            arb,1910            arb,1911            arb,1912          ],1913        },1914      },1915    });1916  });1917  suite ('Object', () => {1918    testLaws ({1919      Setoid: {1920        module: laws.Setoid,1921        laws: {1922          reflexivity: [1923            jsc.dict (jsc.array (jsc.number)),1924          ],1925          symmetry: [1926            jsc.dict (jsc.array (jsc.number)),1927            jsc.dict (jsc.array (jsc.number)),1928          ],1929          transitivity: [1930            jsc.dict (jsc.array (jsc.number)),1931            jsc.dict (jsc.array (jsc.number)),1932            jsc.dict (jsc.array (jsc.number)),1933          ],1934        },1935      },1936      Ord: {1937        module: laws.Ord,1938        laws: {1939          totality: [1940            jsc.dict (jsc.array (jsc.number)),1941            jsc.dict (jsc.array (jsc.number)),1942          ],1943          antisymmetry: [1944            jsc.dict (jsc.array (jsc.number)),1945            jsc.dict (jsc.array (jsc.number)),1946          ],1947          transitivity: [1948            jsc.dict (jsc.array (jsc.number)),1949            jsc.dict (jsc.array (jsc.number)),1950            jsc.dict (jsc.array (jsc.number)),1951          ],1952        },1953      },1954      Semigroup: {1955        module: laws.Semigroup (Z.equals),1956        laws: {1957          associativity: [1958            jsc.dict (jsc.array (jsc.number)),1959            jsc.dict (jsc.array (jsc.number)),1960            jsc.dict (jsc.array (jsc.number)),1961          ],1962        },1963      },1964      Monoid: {1965        module: laws.Monoid (Z.equals, Object),1966        laws: {1967          leftIdentity: [1968            jsc.dict (jsc.array (jsc.number)),1969          ],1970          rightIdentity: [1971            jsc.dict (jsc.array (jsc.number)),1972          ],1973        },1974      },1975      Filterable: {1976        module: laws.Filterable (Z.equals),1977        laws: {1978          distributivity: [1979            jsc.dict (jsc.array (jsc.number)),1980            jsc.constant (xs => xs.length % 2 === 0),1981            jsc.constant (compose (gt (0)) (sum)),1982          ],1983          identity: [1984            jsc.dict (jsc.array (jsc.number)),1985          ],1986          annihilation: [1987            jsc.dict (jsc.array (jsc.number)),1988            jsc.dict (jsc.array (jsc.number)),1989          ],1990        },1991      },1992      Functor: {1993        module: laws.Functor (Z.equals),1994        laws: {1995          identity: [1996            jsc.dict (jsc.array (jsc.number)),1997          ],1998          composition: [1999            jsc.dict (jsc.array (jsc.number)),2000            jsc.constant (Math.round),2001            jsc.constant (sum),2002          ],2003        },2004      },2005      Apply: {2006        module: laws.Apply (Z.equals),2007        laws: {2008          composition: [2009            jsc.dict (jsc.constant (Math.round)),2010            jsc.dict (jsc.constant (sum)),2011            jsc.dict (jsc.array (jsc.number)),2012          ],2013        },2014      },2015      Alt: {2016        module: laws.Alt (Z.equals),2017        laws: {2018          associativity: [2019            jsc.dict (jsc.array (jsc.number)),2020            jsc.dict (jsc.array (jsc.number)),2021            jsc.dict (jsc.array (jsc.number)),2022          ],2023          distributivity: [2024            jsc.dict (jsc.array (jsc.number)),2025            jsc.dict (jsc.array (jsc.number)),2026            jsc.constant (sum),2027          ],2028        },2029      },2030      Plus: {2031        module: laws.Plus (Z.equals, Object),2032        laws: {2033          leftIdentity: [2034            jsc.dict (jsc.array (jsc.number)),2035          ],2036          rightIdentity: [2037            jsc.dict (jsc.array (jsc.number)),2038          ],2039          annihilation: [2040            jsc.constant (sum),2041          ],2042        },2043      },2044      Foldable: {2045        module: laws.Foldable (Z.equals),2046        laws: {2047          associativity: [2048            jsc.constant (Z.concat),2049            jsc.array (jsc.number),2050            jsc.dict (jsc.array (jsc.number)),2051          ],2052        },2053      },2054      Traversable: {2055        module: laws.Traversable (Z.equals),2056        laws: {2057          naturality: [2058            jsc.constant (List),2059            jsc.constant (Array),2060            jsc.constant (listToArray),2061            jsc.dict (ListArb (jsc.number)),2062          ],2063          identity: [2064            jsc.constant (Identity),2065            jsc.dict (jsc.array (jsc.number)),2066          ],2067          composition: [2068            jsc.constant (Maybe),2069            jsc.constant (List),2070            jsc.dict (MaybeArb (ListArb (jsc.number))),2071          ],2072        },2073      },2074    });2075  });2076  suite ('Function', () => {2077    const resultsEqual = x => (f, g) => Z.equals (f (x), g (x));2078    const arb = jsc.oneof (jsc.constant (abs), jsc.constant (square));2079    testLaws ({2080      Setoid: {2081        module: laws.Setoid,2082        laws: {2083          reflexivity: [2084            arb,2085          ],2086          symmetry: [2087            arb,2088            arb,2089          ],2090          transitivity: [2091            arb,2092            arb,2093            arb,2094          ],2095        },2096      },2097      Semigroupoid: {2098        module: laws.Semigroupoid (resultsEqual (['foo', 'bar', 'baz'])),2099        laws: {2100          associativity: [2101            jsc.constant (square),2102            jsc.constant (length),2103            jsc.constant (joinWith ('')),2104          ],2105        },2106      },2107      Category: {2108        module: laws.Category (resultsEqual (['foo', 'bar', 'baz'])),2109        laws: {2110          leftIdentity: [2111            jsc.constant (Function),2112            jsc.constant (joinWith ('')),2113          ],2114          rightIdentity: [2115            jsc.constant (Function),2116            jsc.constant (joinWith ('')),2117          ],2118        },2119      },2120      Functor: {2121        module: laws.Functor (resultsEqual (['foo', 'bar', 'baz'])),2122        laws: {2123          identity: [2124            jsc.constant (Z.reverse),2125          ],2126          composition: [2127            jsc.constant (Z.reverse),2128            jsc.constant (splitOn ('a')),2129            jsc.constant (joinWith ('-')),2130          ],2131        },2132      },2133      Profunctor: {2134        module: laws.Profunctor (resultsEqual (['foo', 'bar', 'baz'])),2135        laws: {2136          identity: [2137            jsc.constant (append ('3')),2138          ],2139          composition: [2140            jsc.constant (append ('3')),2141            jsc.constant (append ('2')),2142            jsc.constant (append ('1')),2143            jsc.constant (append ('5')),2144            jsc.constant (append ('4')),2145          ],2146        },2147      },2148      Apply: {2149        module: laws.Apply (resultsEqual (['foo', 'bar', 'baz'])),2150        laws: {2151          composition: [2152            jsc.constant (xs => x => [x].concat (xs)),2153            jsc.constant (xs => n => xs[n - 1]),2154            jsc.constant (length),2155          ],2156        },2157      },2158      Applicative: {2159        module: laws.Applicative (resultsEqual (['foo', 'bar', 'baz']), Function),2160        laws: {2161          identity: [2162            jsc.constant (length),2163          ],2164          homomorphism: [2165            jsc.constant (joinWith ('')),2166            jsc.array (jsc.string),2167          ],2168          interchange: [2169            jsc.constant (concat),2170            jsc.array (jsc.string),2171          ],2172        },2173      },2174      Chain: {2175        module: laws.Chain (resultsEqual (['foo', 'bar', 'baz'])),2176        laws: {2177          associativity: [2178            jsc.constant (length),2179            jsc.constant (n => xs => xs[n - 1]),2180            jsc.constant (x => xs => [x].concat (xs)),2181          ],2182        },2183      },2184      ChainRec: {2185        module: laws.ChainRec (resultsEqual ({step: 2, inc: 100}), Function),2186        laws: {2187          equivalence: [2188            jsc.constant (n => n === 3000),2189            jsc.constant (n => env => n + env.step),2190            jsc.constant (n => env => n + env.inc),2191            jsc.constant (0),2192          ],2193        },2194      },2195      Monad: {2196        module: laws.Monad (resultsEqual (['foo', 'bar', 'baz']), Function),2197        laws: {2198          leftIdentity: [2199            jsc.constant (compose (joinWith ('-'))),2200            jsc.constant (Z.reverse),2201          ],2202          rightIdentity: [2203            jsc.constant (Z.reverse),2204          ],2205        },2206      },2207      Extend: {2208        module: laws.Extend (resultsEqual (['foo', 'bar', 'baz'])),2209        laws: {2210          associativity: [2211            jsc.constant (Z.reverse),2212            jsc.constant (f => f (['(w b) -> c'])),2213            jsc.constant (f => f (['(w a) -> b'])),2214          ],2215        },2216      },2217      Contravariant: {2218        module: laws.Contravariant (resultsEqual (['foo', 'bar', 'baz'])),2219        laws: {2220          identity: [2221            jsc.constant (Z.reverse),2222          ],2223          composition: [2224            jsc.constant (Z.reverse),2225            jsc.constant (splitOn ('a')),2226            jsc.constant (joinWith ('-')),2227          ],2228        },2229      },2230    });2231  });...MixedCaseArbitrary.ts
Source:MixedCaseArbitrary.ts  
1import { Random } from '../../random/generator/Random';2import { Stream } from '../../stream/Stream';3import { bigUintN } from '../bigUintN';4import { Arbitrary } from '../../check/arbitrary/definition/Arbitrary';5import { Value } from '../../check/arbitrary/definition/Value';6import { makeLazy } from '../../stream/LazyIterableIterator';7import {8  applyFlagsOnChars,9  computeFlagsFromChars,10  computeNextFlags,11  computeTogglePositions,12} from './helpers/ToggleFlags';13import { safeJoin, safeSlice } from '../../utils/globals';14import { BigInt } from '../../utils/globals';15/** @internal */16type MixedCaseArbitraryContext = {17  rawString: string;18  rawStringContext: unknown;19  flags: bigint;20  flagsContext: unknown;21};22/** @internal */23export class MixedCaseArbitrary extends Arbitrary<string> {24  constructor(25    private readonly stringArb: Arbitrary<string>,26    private readonly toggleCase: (rawChar: string) => string,27    private readonly untoggleAll: ((toggledString: string) => string) | undefined28  ) {29    super();30  }31  /**32   * Create a proper context33   * @param rawStringValue34   * @param flagsValue35   */36  private buildContextFor(rawStringValue: Value<string>, flagsValue: Value<bigint>): MixedCaseArbitraryContext {37    return {38      rawString: rawStringValue.value,39      rawStringContext: rawStringValue.context,40      flags: flagsValue.value,41      flagsContext: flagsValue.context,42    };43  }44  generate(mrng: Random, biasFactor: number | undefined): Value<string> {45    const rawStringValue = this.stringArb.generate(mrng, biasFactor);46    const chars = [...rawStringValue.value]; // split into valid unicode (keeps surrogate pairs)47    const togglePositions = computeTogglePositions(chars, this.toggleCase);48    const flagsArb = bigUintN(togglePositions.length);49    const flagsValue = flagsArb.generate(mrng, undefined); // true => toggle the char, false => keep it as-is50    applyFlagsOnChars(chars, flagsValue.value, togglePositions, this.toggleCase);51    return new Value(safeJoin(chars, ''), this.buildContextFor(rawStringValue, flagsValue));52  }53  canShrinkWithoutContext(value: unknown): value is string {54    if (typeof value !== 'string') {55      return false;56    }57    return this.untoggleAll !== undefined58      ? this.stringArb.canShrinkWithoutContext(this.untoggleAll(value))59      : // If nothing was toggled or if the underlying generator can still shrink it, we consider it shrinkable60        this.stringArb.canShrinkWithoutContext(value);61  }62  shrink(value: string, context?: unknown): Stream<Value<string>> {63    let contextSafe: MixedCaseArbitraryContext;64    if (context !== undefined) {65      contextSafe = context as MixedCaseArbitraryContext;66    } else {67      // As user should have called canShrinkWithoutContext first;68      // We know that the untoggled string can be shrunk without any context69      if (this.untoggleAll !== undefined) {70        const untoggledValue = this.untoggleAll(value);71        const valueChars = [...value];72        const untoggledValueChars = [...untoggledValue];73        const togglePositions = computeTogglePositions(untoggledValueChars, this.toggleCase);74        contextSafe = {75          rawString: untoggledValue,76          rawStringContext: undefined,77          flags: computeFlagsFromChars(untoggledValueChars, valueChars, togglePositions),78          flagsContext: undefined,79        };80      } else {81        contextSafe = {82          rawString: value,83          rawStringContext: undefined,84          flags: BigInt(0),85          flagsContext: undefined,86        };87      }88    }89    const rawString = contextSafe.rawString;90    const flags = contextSafe.flags;91    return this.stringArb92      .shrink(rawString, contextSafe.rawStringContext)93      .map((nRawStringValue) => {94        const nChars = [...nRawStringValue.value];95        const nTogglePositions = computeTogglePositions(nChars, this.toggleCase);96        const nFlags = computeNextFlags(flags, nTogglePositions.length);97        // Potentially new value for nTogglePositions.length, new value for nFlags98        // so flagsContext is not applicable anymore99        applyFlagsOnChars(nChars, nFlags, nTogglePositions, this.toggleCase);100        // Remark: Value nFlags can be attached to a context equal to undefined101        // as `canShrinkWithoutContext(nFlags) === true` for the bigint arbitrary102        return new Value(safeJoin(nChars, ''), this.buildContextFor(nRawStringValue, new Value(nFlags, undefined)));103      })104      .join(105        makeLazy(() => {106          const chars = [...rawString];107          const togglePositions = computeTogglePositions(chars, this.toggleCase);108          return bigUintN(togglePositions.length)109            .shrink(flags, contextSafe.flagsContext)110            .map((nFlagsValue) => {111              const nChars = safeSlice(chars); // cloning chars112              applyFlagsOnChars(nChars, nFlagsValue.value, togglePositions, this.toggleCase);113              return new Value(114                safeJoin(nChars, ''),115                this.buildContextFor(new Value(rawString, contextSafe.rawStringContext), nFlagsValue)116              );117            });118        })119      );120  }...Using AI Code Generation
1const fc = require('fast-check');2const flagsArb = require('fast-check-monorepo').flagsArb;3fc.assert(4    fc.property(flagsArb(), (flags) => {5        console.log(flags);6        return true;7    }),8);9const fc = require('fast-check');10test('test', () => {11    fc.assert(12        fc.property(fc.integer(), (x) => {13            expect(x).toBeGreaterThanOrEqual(0);14        }),15    );16});17at Object.<anonymous> (node_modules/fast-check/lib/check/arbitrary/FlagsArbitrary.js:12:31)18const fc = require('fast-check');19test('test', () => {20    fc.assert(21        fc.property(fc.integer(), (x) => {22            expect(x).toBeGreaterThanOrEqual(0);23        }),24    );25});26at Object.<anonymous> (node_modules/fast-check/lib/check/arbitrary/FlagsArbitrary.js:12:31)27const fc = require('fast-check');28test('test', () => {29    fc.assert(30        fc.property(fc.integer(), (x) => {31            expect(x).toBeGreaterThanOrEqual(0);32        }),33    );34});35at Object.<anonymous> (node_modules/fast-check/lib/check/arbitrary/FlagsArbitrary.js:12:31)Using AI Code Generation
1const fc = require('fast-check');2fc.flagsArb().map(flags => {3    console.log(flags);4});5const fc = require('fast-check');6fc.flagsArb().map(flags => {7    console.log(flags);8});Using AI Code Generation
1const fc = require('fast-check');2const flagsArb = require('fast-check/lib/arbitrary/flagsArb');3const flag = require('fast-check/lib/arbitrary/flag');4const { flags } = require('fast-check/lib/arbitrary/flags');5const flagsArb2 = flagsArb(flags(flag('a'), flag('b'), flag('c')));6fc.assert(7  fc.property(flagsArb2, flags => {8    console.log(flags);9    return true;10  })11);Using AI Code Generation
1const fc = require('fast-check');2const { flagsArb } = require('fast-check/lib/arbitrary/_internals/FlagsArbitrary');3const flagsArbTest = flagsArb(3);4flagsArbTest.generate(1, 1);5const flagsArbTest1 = fc.flagsArb(3);6flagsArbTest1.generate(1, 1);7  throw err;8    at Function.Module._resolveFilename (internal/modules/cjs/loader.js:880:15)9    at Function.Module._load (internal/modules/cjs/loader.js:725:27)10    at Module.require (internal/modules/cjs/loader.js:952:19)11    at require (internal/modules/cjs/helpers.js:88:18)12    at Object.<anonymous> (C:\Users\user\Documents\fast-check-monorepo\fast-check-monorepo\test3\test3.js:3:18)13    at Module._compile (internal/modules/cjs/loader.js:1063:30)14    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1092:10)15    at Module.load (internal/modules/cjs/loader.js:928:32)16    at Function.Module._load (internal/modules/cjs/loader.js:769:14)17    at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:72:12) {18}Using AI Code Generation
1const fc = require('fast-check');2const arb = fc.flagsArb(fc.integer());3fc.assert(fc.property(arb, (flags) => {4    console.log(flags);5    return true;6}));7const fc = require('fast-check');8const arb = fc.flagsArb(fc.integer());9fc.assert(fc.property(arb, (flags) => {10    console.log(flags);11    return true;12}));13const fc = require('fast-check');14const arb = fc.flagsArb(fc.integer());15fc.assert(fc.property(arb, (flags) => {16    console.log(flags);17    return true;18}));19const fc = require('fast-check');20const arb = fc.flagsArb(fc.integer());21fc.assert(fc.property(arb, (flags) => {22    console.log(flags);23    return true;24}));25const fc = require('fast-check');26const arb = fc.flagsArb(fc.integer());27fc.assert(fc.property(arb, (flags) => {28    console.log(flags);29    return true;30}));31const fc = require('fast-check');32const arb = fc.flagsArb(fc.integer());33fc.assert(fc.property(arb, (flags) => {34    console.log(flags);35    return true;36}));37const fc = require('fast-check');38const arb = fc.flagsArb(fc.integer());39fc.assert(fc.property(arb, (flags) => {40    console.log(flags);41    return true;42}));43const fc = require('fast-check');44const arb = fc.flagsArb(fc.integer());45fc.assert(fc.property(arb, (flags) => {46    console.log(flags);47    return true;48}));Using AI Code Generation
1const fc = require('fast-check');2fc.configureGlobal({verbose: true});3fc.assert(4  fc.property(5    fc.flagsArb(6      {flags: ['a', 'b', 'c']},7      {num: 1, build: (flags) => flags.join('')},8      {num: 2, build: (flags) => flags.join('')}9    (flags) => {10      console.log('flags:', flags);11      return true;12    }13);14const fc = require('fast-check');15fc.configureGlobal({verbose: true});16fc.assert(17  fc.property(18    fc.flagsArb(19      {flags: ['a', 'b', 'c']},20      {num: 1, build: (flags) => flags.join('')},21      {num: 2, build: (flags) => flags.join('')}22    (flags) => {23      console.log('flags:', flags);24      return true;25    }26);27const fc = require('fast-check');28fc.configureGlobal({verbose: true});29fc.assert(30  fc.property(31    fc.flagsArb(32      {flags: ['a', 'b', 'c']},33      {num: 1, build: (flags) => flags.join('')},34      {num: 2, build: (flags) => flags.join('')}35    (flags) => {36      console.log('flags:', flags);37      return true;38    }39);40const fc = require('fast-check');41fc.configureGlobal({verbose: true});42fc.assert(43  fc.property(44    fc.flagsArb(45      {flags: ['a', 'b', 'c']},46      {num: 1, build: (flags) => flags.join('')},47      {num: 2, build: (flags) => flags.join('')}48    (flags) => {49      console.log('flags:', flags);50      return true;51    }52);Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!
