lawspec 0.30.0 → 0.31.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +405 -1
- package/README.md +19 -7
- package/api.mjs +1 -0
- package/beam-doctor.mjs +2 -2
- package/bin/lawspec.mjs +104 -96
- package/build.json +498 -406
- package/component-packages.mjs +339 -0
- package/component.d.ts +46 -0
- package/component.mjs +208 -0
- package/core.wasm +2 -2
- package/core_jsffi.js +5 -5
- package/examples/native-payments/clojure/lawspec.edn +48 -0
- package/examples/native-payments/clojure/src/domain/payments.clj +1 -1
- package/examples/native-payments/clojure/test/domain/payment_generators.clj +1 -1
- package/examples/native-payments/csharp/lawspec.edn +48 -0
- package/examples/native-payments/elixir/lawspec.edn +123 -0
- package/examples/native-payments/erlang/lawspec.edn +128 -0
- package/examples/native-payments/fsharp/lawspec.edn +123 -0
- package/examples/native-payments/gleam/lawspec.edn +123 -0
- package/examples/native-payments/go/lawspec.edn +123 -0
- package/examples/native-payments/groovy/lawspec.edn +123 -0
- package/examples/native-payments/haskell/lawspec.edn +123 -0
- package/examples/native-payments/java/lawspec.edn +123 -0
- package/examples/native-payments/javascript/lawspec.edn +123 -0
- package/examples/native-payments/kotlin/lawspec.edn +123 -0
- package/examples/native-payments/prolog/lawspec.edn +48 -0
- package/examples/native-payments/python/lawspec.edn +123 -0
- package/examples/native-payments/rust/lawspec.edn +124 -0
- package/examples/native-payments/scala/lawspec.edn +123 -0
- package/examples/native-payments/swift/lawspec.edn +123 -0
- package/examples/native-payments/typescript/lawspec.edn +123 -0
- package/examples/packages/orders/lawspec.edn +25 -0
- package/examples/packages/shop-domain/lawspec.edn +13 -0
- package/examples/packages/shop-tax-1/lawspec.edn +9 -0
- package/examples/packages/shop-tax-2/lawspec.edn +9 -0
- package/examples/specs/handler_bindings.lawspec +2 -2
- package/files.mjs +2 -1
- package/go.mod +4 -0
- package/index.d.ts +135 -2
- package/input-files.mjs +47 -0
- package/launcher.mjs +33 -13
- package/learn/adapters.mjs +226 -0
- package/learn/app.mjs +1279 -0
- package/learn/assert.mjs +33 -0
- package/learn/assets.mjs +15 -0
- package/learn/browser-runtime.mjs +58 -0
- package/learn/bundle.mjs +118 -0
- package/learn/compile-worker.mjs +106 -0
- package/learn/compiler.mjs +230 -0
- package/learn/coverage.json +8187 -0
- package/learn/curriculum.json +2952 -0
- package/learn/fantomas-worker.mjs +25 -0
- package/learn/format-worker.mjs +148 -0
- package/learn/fsharp.mjs +83 -0
- package/learn/harness-host.mjs +22 -0
- package/learn/index.html +326 -0
- package/learn/lawspec-core.mjs +223 -0
- package/learn/lawspec-language.mjs +69 -0
- package/learn/node-test.mjs +11 -0
- package/learn/presentation.mjs +73 -0
- package/learn/runner.mjs +72 -0
- package/learn/sandbox-frame.html +34 -0
- package/learn/sandbox.mjs +91 -0
- package/learn/store.mjs +141 -0
- package/learn/story.mjs +42 -0
- package/learn/style-options.json +16 -0
- package/learn/style.css +1023 -0
- package/learn/theme.js +77 -0
- package/learn/typescript.mjs +53 -0
- package/learn/vendor/@fontsource-atkinson-hyperlegible-LICENSE.txt +93 -0
- package/learn/vendor/@fontsource-atkinson-hyperlegible-mono-LICENSE.txt +93 -0
- package/learn/vendor/@fontsource-overpass-LICENSE.txt +93 -0
- package/learn/vendor/assemblies.json +1 -0
- package/learn/vendor/editor-worker.js +30 -0
- package/learn/vendor/editor.css +1 -0
- package/learn/vendor/editor.mjs +931 -0
- package/learn/vendor/esbuild-wasm-LICENSE.txt +21 -0
- package/learn/vendor/esbuild.mjs +2683 -0
- package/learn/vendor/esbuild.wasm +0 -0
- package/learn/vendor/fable-library/Array.js +1347 -0
- package/learn/vendor/fable-library/Async.js +134 -0
- package/learn/vendor/fable-library/AsyncBuilder.js +183 -0
- package/learn/vendor/fable-library/BigInt.js +306 -0
- package/learn/vendor/fable-library/BitConverter.js +138 -0
- package/learn/vendor/fable-library/Boolean.js +22 -0
- package/learn/vendor/fable-library/CHANGELOG.md +242 -0
- package/learn/vendor/fable-library/Char.js +202 -0
- package/learn/vendor/fable-library/Choice.js +184 -0
- package/learn/vendor/fable-library/CollectionUtil.js +182 -0
- package/learn/vendor/fable-library/ConditionalWeakTable.js +21 -0
- package/learn/vendor/fable-library/Date.js +841 -0
- package/learn/vendor/fable-library/DateOffset.js +261 -0
- package/learn/vendor/fable-library/DateOnly.js +124 -0
- package/learn/vendor/fable-library/Decimal.js +238 -0
- package/learn/vendor/fable-library/Double.js +47 -0
- package/learn/vendor/fable-library/Encoding.js +185 -0
- package/learn/vendor/fable-library/Event.js +93 -0
- package/learn/vendor/fable-library/FSharp.Collections.js +45 -0
- package/learn/vendor/fable-library/FSharp.Core.CompilerServices.js +27 -0
- package/learn/vendor/fable-library/FSharp.Core.js +156 -0
- package/learn/vendor/fable-library/Global.js +29 -0
- package/learn/vendor/fable-library/Guid.js +161 -0
- package/learn/vendor/fable-library/Int32.js +135 -0
- package/learn/vendor/fable-library/List.js +1323 -0
- package/learn/vendor/fable-library/Long.js +47 -0
- package/learn/vendor/fable-library/MailboxProcessor.js +94 -0
- package/learn/vendor/fable-library/Map.js +1396 -0
- package/learn/vendor/fable-library/MapUtil.js +130 -0
- package/learn/vendor/fable-library/MutableMap.js +339 -0
- package/learn/vendor/fable-library/MutableSet.js +233 -0
- package/learn/vendor/fable-library/Native.js +14 -0
- package/learn/vendor/fable-library/Numeric.js +75 -0
- package/learn/vendor/fable-library/Observable.js +113 -0
- package/learn/vendor/fable-library/Option.js +104 -0
- package/learn/vendor/fable-library/README.md +3 -0
- package/learn/vendor/fable-library/Random.js +172 -0
- package/learn/vendor/fable-library/Range.js +45 -0
- package/learn/vendor/fable-library/Reflection.js +479 -0
- package/learn/vendor/fable-library/RegExp.js +141 -0
- package/learn/vendor/fable-library/Result.js +165 -0
- package/learn/vendor/fable-library/Seq.js +1417 -0
- package/learn/vendor/fable-library/Seq2.js +111 -0
- package/learn/vendor/fable-library/Set.js +1816 -0
- package/learn/vendor/fable-library/String.js +674 -0
- package/learn/vendor/fable-library/System.Collections.Generic.js +333 -0
- package/learn/vendor/fable-library/System.Text.js +200 -0
- package/learn/vendor/fable-library/System.js +289 -0
- package/learn/vendor/fable-library/TimeOnly.js +122 -0
- package/learn/vendor/fable-library/TimeSpan.js +180 -0
- package/learn/vendor/fable-library/Timer.js +67 -0
- package/learn/vendor/fable-library/Types.js +198 -0
- package/learn/vendor/fable-library/Unicode.13.0.0.js +4 -0
- package/learn/vendor/fable-library/Uri.js +165 -0
- package/learn/vendor/fable-library/Util.js +796 -0
- package/learn/vendor/fable-library/big.d.ts +338 -0
- package/learn/vendor/fable-library/lib/big.js +825 -0
- package/learn/vendor/fable-library/package.json +24 -0
- package/learn/vendor/fable-library/quotation.js +618 -0
- package/learn/vendor/fable.js +430 -0
- package/learn/vendor/fantomas/FSharp.Core.uawo19tl4c.wasm +0 -0
- package/learn/vendor/fantomas/Fantomas.Core.stnanlnpyw.wasm +0 -0
- package/learn/vendor/fantomas/Fantomas.FCS.lqohfu5o9y.wasm +0 -0
- package/learn/vendor/fantomas/LawSpec.Learn.Formatter.5arcua4vy0.wasm +0 -0
- package/learn/vendor/fantomas/LawSpec.Learn.Formatter.u1ne3a6xd2.wasm +0 -0
- package/learn/vendor/fantomas/Microsoft.CSharp.mp8lhr6rez.wasm +0 -0
- package/learn/vendor/fantomas/Microsoft.VisualBasic.0e5fchkecn.wasm +0 -0
- package/learn/vendor/fantomas/Microsoft.VisualBasic.Core.17wn27qal2.wasm +0 -0
- package/learn/vendor/fantomas/Microsoft.Win32.Primitives.9d566sle9e.wasm +0 -0
- package/learn/vendor/fantomas/Microsoft.Win32.Registry.52dy96yk8i.wasm +0 -0
- package/learn/vendor/fantomas/System.AppContext.jwujeh069z.wasm +0 -0
- package/learn/vendor/fantomas/System.Buffers.y0isk1x97h.wasm +0 -0
- package/learn/vendor/fantomas/System.Collections.Concurrent.x5koi7bzem.wasm +0 -0
- package/learn/vendor/fantomas/System.Collections.Immutable.diwg7advch.wasm +0 -0
- package/learn/vendor/fantomas/System.Collections.NonGeneric.4089xs440e.wasm +0 -0
- package/learn/vendor/fantomas/System.Collections.Specialized.hj81u7zblb.wasm +0 -0
- package/learn/vendor/fantomas/System.Collections.nvrdeoknr1.wasm +0 -0
- package/learn/vendor/fantomas/System.ComponentModel.Annotations.yatcnfjeuk.wasm +0 -0
- package/learn/vendor/fantomas/System.ComponentModel.DataAnnotations.led9l5awu3.wasm +0 -0
- package/learn/vendor/fantomas/System.ComponentModel.EventBasedAsync.hpvp6cf4de.wasm +0 -0
- package/learn/vendor/fantomas/System.ComponentModel.Primitives.v7cajwpaqo.wasm +0 -0
- package/learn/vendor/fantomas/System.ComponentModel.TypeConverter.xk1hnyt762.wasm +0 -0
- package/learn/vendor/fantomas/System.ComponentModel.rrnda1lucx.wasm +0 -0
- package/learn/vendor/fantomas/System.Configuration.bn9vghjcq8.wasm +0 -0
- package/learn/vendor/fantomas/System.Console.09ajpiafhz.wasm +0 -0
- package/learn/vendor/fantomas/System.Core.wc649o5mw9.wasm +0 -0
- package/learn/vendor/fantomas/System.Data.Common.s4cowzd9a9.wasm +0 -0
- package/learn/vendor/fantomas/System.Data.DataSetExtensions.5fm360ikxl.wasm +0 -0
- package/learn/vendor/fantomas/System.Data.fsu4j4t4jw.wasm +0 -0
- package/learn/vendor/fantomas/System.Diagnostics.Contracts.p74re5oxzn.wasm +0 -0
- package/learn/vendor/fantomas/System.Diagnostics.Debug.622sixg49n.wasm +0 -0
- package/learn/vendor/fantomas/System.Diagnostics.DiagnosticSource.2j35bc2g2b.wasm +0 -0
- package/learn/vendor/fantomas/System.Diagnostics.FileVersionInfo.7n0wdvltaa.wasm +0 -0
- package/learn/vendor/fantomas/System.Diagnostics.Process.8iffh49mew.wasm +0 -0
- package/learn/vendor/fantomas/System.Diagnostics.StackTrace.1yz88vico8.wasm +0 -0
- package/learn/vendor/fantomas/System.Diagnostics.TextWriterTraceListener.ua8iuh2vhj.wasm +0 -0
- package/learn/vendor/fantomas/System.Diagnostics.Tools.roy5445ugj.wasm +0 -0
- package/learn/vendor/fantomas/System.Diagnostics.TraceSource.6qx1ldzz7g.wasm +0 -0
- package/learn/vendor/fantomas/System.Diagnostics.Tracing.b4799zpaas.wasm +0 -0
- package/learn/vendor/fantomas/System.Drawing.8gcjjqj0pu.wasm +0 -0
- package/learn/vendor/fantomas/System.Drawing.Primitives.y2uveru2yk.wasm +0 -0
- package/learn/vendor/fantomas/System.Dynamic.Runtime.023zrvzh9x.wasm +0 -0
- package/learn/vendor/fantomas/System.Formats.Asn1.znpklkbgqv.wasm +0 -0
- package/learn/vendor/fantomas/System.Formats.Tar.5yybjepfi2.wasm +0 -0
- package/learn/vendor/fantomas/System.Globalization.Calendars.10g6hyjy3k.wasm +0 -0
- package/learn/vendor/fantomas/System.Globalization.Extensions.hrinfrismg.wasm +0 -0
- package/learn/vendor/fantomas/System.Globalization.uvs4rah8fk.wasm +0 -0
- package/learn/vendor/fantomas/System.IO.4j645gw40d.wasm +0 -0
- package/learn/vendor/fantomas/System.IO.Compression.2z7vdt6tfb.wasm +0 -0
- package/learn/vendor/fantomas/System.IO.Compression.Brotli.fv80xs79j3.wasm +0 -0
- package/learn/vendor/fantomas/System.IO.Compression.FileSystem.88jdddz3sw.wasm +0 -0
- package/learn/vendor/fantomas/System.IO.Compression.ZipFile.jkn9avr4vo.wasm +0 -0
- package/learn/vendor/fantomas/System.IO.FileSystem.AccessControl.yme0uhbu37.wasm +0 -0
- package/learn/vendor/fantomas/System.IO.FileSystem.DriveInfo.qas7wf73rs.wasm +0 -0
- package/learn/vendor/fantomas/System.IO.FileSystem.Primitives.d1jmhkzu0e.wasm +0 -0
- package/learn/vendor/fantomas/System.IO.FileSystem.Watcher.z570derp0d.wasm +0 -0
- package/learn/vendor/fantomas/System.IO.FileSystem.o6jtz51fup.wasm +0 -0
- package/learn/vendor/fantomas/System.IO.IsolatedStorage.hqyeyb5ipe.wasm +0 -0
- package/learn/vendor/fantomas/System.IO.MemoryMappedFiles.zhamjnusxd.wasm +0 -0
- package/learn/vendor/fantomas/System.IO.Pipelines.wrmw5vws31.wasm +0 -0
- package/learn/vendor/fantomas/System.IO.Pipes.AccessControl.qcancj8gj2.wasm +0 -0
- package/learn/vendor/fantomas/System.IO.Pipes.zhcyguvwkr.wasm +0 -0
- package/learn/vendor/fantomas/System.IO.UnmanagedMemoryStream.o8cpjnlard.wasm +0 -0
- package/learn/vendor/fantomas/System.Linq.AsyncEnumerable.hyc0b7okjw.wasm +0 -0
- package/learn/vendor/fantomas/System.Linq.Expressions.ldibvm0efj.wasm +0 -0
- package/learn/vendor/fantomas/System.Linq.Parallel.2buevezvch.wasm +0 -0
- package/learn/vendor/fantomas/System.Linq.Queryable.cvq43g1awj.wasm +0 -0
- package/learn/vendor/fantomas/System.Linq.lz6mvi0hm2.wasm +0 -0
- package/learn/vendor/fantomas/System.Memory.3jekerw0ga.wasm +0 -0
- package/learn/vendor/fantomas/System.Net.Http.Json.8k237kkwec.wasm +0 -0
- package/learn/vendor/fantomas/System.Net.Http.cityx2bvcl.wasm +0 -0
- package/learn/vendor/fantomas/System.Net.HttpListener.s1jreclykx.wasm +0 -0
- package/learn/vendor/fantomas/System.Net.Mail.cmlj4c0gto.wasm +0 -0
- package/learn/vendor/fantomas/System.Net.NameResolution.q3gf18q13l.wasm +0 -0
- package/learn/vendor/fantomas/System.Net.NetworkInformation.xaz5tjw7d0.wasm +0 -0
- package/learn/vendor/fantomas/System.Net.Ping.a40atim1h0.wasm +0 -0
- package/learn/vendor/fantomas/System.Net.Primitives.i88i20r8sr.wasm +0 -0
- package/learn/vendor/fantomas/System.Net.Quic.hx06eo5xkj.wasm +0 -0
- package/learn/vendor/fantomas/System.Net.Requests.hkjxlfe5f5.wasm +0 -0
- package/learn/vendor/fantomas/System.Net.Security.ch34yya69o.wasm +0 -0
- package/learn/vendor/fantomas/System.Net.ServerSentEvents.0u7o0jk3p1.wasm +0 -0
- package/learn/vendor/fantomas/System.Net.ServicePoint.xbhxnytx4l.wasm +0 -0
- package/learn/vendor/fantomas/System.Net.Sockets.hzgzlvkc9l.wasm +0 -0
- package/learn/vendor/fantomas/System.Net.WebClient.84i8nwzbgu.wasm +0 -0
- package/learn/vendor/fantomas/System.Net.WebHeaderCollection.326nl7s9g3.wasm +0 -0
- package/learn/vendor/fantomas/System.Net.WebProxy.oq3mgkkqef.wasm +0 -0
- package/learn/vendor/fantomas/System.Net.WebSockets.2cx1v74vg8.wasm +0 -0
- package/learn/vendor/fantomas/System.Net.WebSockets.Client.rafzkktw8j.wasm +0 -0
- package/learn/vendor/fantomas/System.Net.w1hpj3bo6r.wasm +0 -0
- package/learn/vendor/fantomas/System.Numerics.Vectors.oyv7biw9ux.wasm +0 -0
- package/learn/vendor/fantomas/System.Numerics.lyu36wqn19.wasm +0 -0
- package/learn/vendor/fantomas/System.ObjectModel.kxu80demuu.wasm +0 -0
- package/learn/vendor/fantomas/System.Private.CoreLib.1vy46s12u6.wasm +0 -0
- package/learn/vendor/fantomas/System.Private.DataContractSerialization.ao8k9iu77a.wasm +0 -0
- package/learn/vendor/fantomas/System.Private.Uri.itn0n2zjd0.wasm +0 -0
- package/learn/vendor/fantomas/System.Private.Xml.19nzpxrx8w.wasm +0 -0
- package/learn/vendor/fantomas/System.Private.Xml.Linq.tw5eq1hjvo.wasm +0 -0
- package/learn/vendor/fantomas/System.Reflection.DispatchProxy.7lajnj8s8c.wasm +0 -0
- package/learn/vendor/fantomas/System.Reflection.Emit.7liz9zln06.wasm +0 -0
- package/learn/vendor/fantomas/System.Reflection.Emit.ILGeneration.1ut3qgacw8.wasm +0 -0
- package/learn/vendor/fantomas/System.Reflection.Emit.Lightweight.d0gvllb1jj.wasm +0 -0
- package/learn/vendor/fantomas/System.Reflection.Extensions.zr5bhwfczd.wasm +0 -0
- package/learn/vendor/fantomas/System.Reflection.Metadata.ff6np6mz2j.wasm +0 -0
- package/learn/vendor/fantomas/System.Reflection.Primitives.igpmvwv78c.wasm +0 -0
- package/learn/vendor/fantomas/System.Reflection.TypeExtensions.qouojzlnp9.wasm +0 -0
- package/learn/vendor/fantomas/System.Reflection.mk3jyxvh13.wasm +0 -0
- package/learn/vendor/fantomas/System.Resources.Reader.41ppfyz2vc.wasm +0 -0
- package/learn/vendor/fantomas/System.Resources.ResourceManager.sfwvfmw1ea.wasm +0 -0
- package/learn/vendor/fantomas/System.Resources.Writer.3uvs9tp38z.wasm +0 -0
- package/learn/vendor/fantomas/System.Runtime.CompilerServices.Unsafe.puz1xm53oc.wasm +0 -0
- package/learn/vendor/fantomas/System.Runtime.CompilerServices.VisualC.9qdau315py.wasm +0 -0
- package/learn/vendor/fantomas/System.Runtime.Extensions.i7gntui96b.wasm +0 -0
- package/learn/vendor/fantomas/System.Runtime.Handles.00oxj4o6ov.wasm +0 -0
- package/learn/vendor/fantomas/System.Runtime.InteropServices.JavaScript.9kq1vofond.wasm +0 -0
- package/learn/vendor/fantomas/System.Runtime.InteropServices.RuntimeInformation.my7qeqbhfh.wasm +0 -0
- package/learn/vendor/fantomas/System.Runtime.InteropServices.vqp80tnwc7.wasm +0 -0
- package/learn/vendor/fantomas/System.Runtime.Intrinsics.u0samjybfo.wasm +0 -0
- package/learn/vendor/fantomas/System.Runtime.Loader.n6zxw1b98a.wasm +0 -0
- package/learn/vendor/fantomas/System.Runtime.Numerics.o40sjhz59x.wasm +0 -0
- package/learn/vendor/fantomas/System.Runtime.Serialization.Formatters.1esvva4te3.wasm +0 -0
- package/learn/vendor/fantomas/System.Runtime.Serialization.Json.4n7u09advh.wasm +0 -0
- package/learn/vendor/fantomas/System.Runtime.Serialization.Primitives.xs2bo91wvk.wasm +0 -0
- package/learn/vendor/fantomas/System.Runtime.Serialization.Xml.ny21jmziti.wasm +0 -0
- package/learn/vendor/fantomas/System.Runtime.Serialization.qcxaur5wqs.wasm +0 -0
- package/learn/vendor/fantomas/System.Runtime.odq454d6j9.wasm +0 -0
- package/learn/vendor/fantomas/System.Security.AccessControl.8yfnzmqzaq.wasm +0 -0
- package/learn/vendor/fantomas/System.Security.Claims.8ogy0860de.wasm +0 -0
- package/learn/vendor/fantomas/System.Security.Cryptography.Algorithms.8zijp1svfw.wasm +0 -0
- package/learn/vendor/fantomas/System.Security.Cryptography.Cng.yxagtt77no.wasm +0 -0
- package/learn/vendor/fantomas/System.Security.Cryptography.Csp.uhfbvvau84.wasm +0 -0
- package/learn/vendor/fantomas/System.Security.Cryptography.Encoding.2ywrusvy8q.wasm +0 -0
- package/learn/vendor/fantomas/System.Security.Cryptography.OpenSsl.oa268u7i92.wasm +0 -0
- package/learn/vendor/fantomas/System.Security.Cryptography.Primitives.5uhvqe8puk.wasm +0 -0
- package/learn/vendor/fantomas/System.Security.Cryptography.X509Certificates.6i7pxilopt.wasm +0 -0
- package/learn/vendor/fantomas/System.Security.Cryptography.d0quqk1iyr.wasm +0 -0
- package/learn/vendor/fantomas/System.Security.Principal.Windows.gpqua4rz29.wasm +0 -0
- package/learn/vendor/fantomas/System.Security.Principal.i20kfklf3g.wasm +0 -0
- package/learn/vendor/fantomas/System.Security.SecureString.x2y8tzci3c.wasm +0 -0
- package/learn/vendor/fantomas/System.Security.e83vvh6sl2.wasm +0 -0
- package/learn/vendor/fantomas/System.ServiceModel.Web.poglliv2no.wasm +0 -0
- package/learn/vendor/fantomas/System.ServiceProcess.yro5uj2opo.wasm +0 -0
- package/learn/vendor/fantomas/System.Text.Encoding.CodePages.2wchx40i7z.wasm +0 -0
- package/learn/vendor/fantomas/System.Text.Encoding.Extensions.8utaw61kn5.wasm +0 -0
- package/learn/vendor/fantomas/System.Text.Encoding.cxdyfepnpj.wasm +0 -0
- package/learn/vendor/fantomas/System.Text.Encodings.Web.37ehbi7cye.wasm +0 -0
- package/learn/vendor/fantomas/System.Text.Json.ixiaa8hd3h.wasm +0 -0
- package/learn/vendor/fantomas/System.Text.RegularExpressions.2fhfmkk6vf.wasm +0 -0
- package/learn/vendor/fantomas/System.Threading.6pry74a050.wasm +0 -0
- package/learn/vendor/fantomas/System.Threading.AccessControl.76zfdfy8go.wasm +0 -0
- package/learn/vendor/fantomas/System.Threading.Channels.gpxnr01lmp.wasm +0 -0
- package/learn/vendor/fantomas/System.Threading.Overlapped.aqpl8tzdyc.wasm +0 -0
- package/learn/vendor/fantomas/System.Threading.Tasks.Dataflow.ytwttt7fzh.wasm +0 -0
- package/learn/vendor/fantomas/System.Threading.Tasks.Extensions.0deavcb00v.wasm +0 -0
- package/learn/vendor/fantomas/System.Threading.Tasks.Parallel.tjwtxugso0.wasm +0 -0
- package/learn/vendor/fantomas/System.Threading.Tasks.fu4qd5h3qy.wasm +0 -0
- package/learn/vendor/fantomas/System.Threading.Thread.klaua2by9m.wasm +0 -0
- package/learn/vendor/fantomas/System.Threading.ThreadPool.mkzm212njz.wasm +0 -0
- package/learn/vendor/fantomas/System.Threading.Timer.yp49llu5h2.wasm +0 -0
- package/learn/vendor/fantomas/System.Transactions.Local.vz6cgeh4w7.wasm +0 -0
- package/learn/vendor/fantomas/System.Transactions.ipwm3rsy66.wasm +0 -0
- package/learn/vendor/fantomas/System.ValueTuple.7ol6ljuhx8.wasm +0 -0
- package/learn/vendor/fantomas/System.Web.HttpUtility.itlvncjd96.wasm +0 -0
- package/learn/vendor/fantomas/System.Web.np8uzzakvl.wasm +0 -0
- package/learn/vendor/fantomas/System.Windows.18nzio44t3.wasm +0 -0
- package/learn/vendor/fantomas/System.Xml.45jprtg1pa.wasm +0 -0
- package/learn/vendor/fantomas/System.Xml.Linq.v9v8udncm1.wasm +0 -0
- package/learn/vendor/fantomas/System.Xml.ReaderWriter.a9mr08uzci.wasm +0 -0
- package/learn/vendor/fantomas/System.Xml.Serialization.03juoguwgc.wasm +0 -0
- package/learn/vendor/fantomas/System.Xml.XDocument.c9dhjnzqjb.wasm +0 -0
- package/learn/vendor/fantomas/System.Xml.XPath.XDocument.138b12i1pm.wasm +0 -0
- package/learn/vendor/fantomas/System.Xml.XPath.pvxm9341ce.wasm +0 -0
- package/learn/vendor/fantomas/System.Xml.XmlDocument.450wsyxvl0.wasm +0 -0
- package/learn/vendor/fantomas/System.Xml.XmlSerializer.y3t2n0tce7.wasm +0 -0
- package/learn/vendor/fantomas/System.gjriafnqmz.wasm +0 -0
- package/learn/vendor/fantomas/WindowsBase.8zsce9qxfb.wasm +0 -0
- package/learn/vendor/fantomas/cs/FSharp.Core.resources.9ehmavdel7.wasm +0 -0
- package/learn/vendor/fantomas/de/FSharp.Core.resources.2ofmxloa01.wasm +0 -0
- package/learn/vendor/fantomas/dotnet.js +1233 -0
- package/learn/vendor/fantomas/dotnet.native.b6l13xorvf.js +16 -0
- package/learn/vendor/fantomas/dotnet.native.rw4kynp763.wasm +0 -0
- package/learn/vendor/fantomas/dotnet.runtime.v06hirbjsv.js +4 -0
- package/learn/vendor/fantomas/es/FSharp.Core.resources.hkr5ggb4tr.wasm +0 -0
- package/learn/vendor/fantomas/fr/FSharp.Core.resources.43soen28ow.wasm +0 -0
- package/learn/vendor/fantomas/icudt_CJK.tjcz0u77k5.dat +0 -0
- package/learn/vendor/fantomas/icudt_EFIGS.tptq2av103.dat +0 -0
- package/learn/vendor/fantomas/icudt_no_CJK.lfu7j35m59.dat +0 -0
- package/learn/vendor/fantomas/it/FSharp.Core.resources.m60n5ls7oq.wasm +0 -0
- package/learn/vendor/fantomas/ja/FSharp.Core.resources.o6oof69v14.wasm +0 -0
- package/learn/vendor/fantomas/ko/FSharp.Core.resources.q6l4snlu9o.wasm +0 -0
- package/learn/vendor/fantomas/mscorlib.8ptuc08eli.wasm +0 -0
- package/learn/vendor/fantomas/netstandard.eymp85mooh.wasm +0 -0
- package/learn/vendor/fantomas/pl/FSharp.Core.resources.8bni0w6j8b.wasm +0 -0
- package/learn/vendor/fantomas/pt-BR/FSharp.Core.resources.k849vqm41u.wasm +0 -0
- package/learn/vendor/fantomas/ru/FSharp.Core.resources.jz9rhhtsla.wasm +0 -0
- package/learn/vendor/fantomas/tr/FSharp.Core.resources.wn6vbvjm1u.wasm +0 -0
- package/learn/vendor/fantomas/zh-Hans/FSharp.Core.resources.z7zzbso094.wasm +0 -0
- package/learn/vendor/fantomas/zh-Hant/FSharp.Core.resources.iammfsi7ls.wasm +0 -0
- package/learn/vendor/fast-check-LICENSE.txt +21 -0
- package/learn/vendor/fast-check.mjs +37 -0
- package/learn/vendor/fonts/atkinson-hyperlegible-latin-400-normal.woff2 +0 -0
- package/learn/vendor/fonts/atkinson-hyperlegible-latin-700-normal.woff2 +0 -0
- package/learn/vendor/fonts/atkinson-hyperlegible-mono-latin-400-normal.woff2 +0 -0
- package/learn/vendor/fonts/overpass-latin-600-normal.woff2 +0 -0
- package/learn/vendor/fonts/overpass-latin-700-normal.woff2 +0 -0
- package/learn/vendor/formatter-licenses/DotNet-LICENSE.txt +23 -0
- package/learn/vendor/formatter-licenses/DotNet-THIRD-PARTY-NOTICES.txt +1418 -0
- package/learn/vendor/formatter-licenses/FSharp-LICENSE.txt +23 -0
- package/learn/vendor/formatter-licenses/Fantomas-LICENSE.txt +202 -0
- package/learn/vendor/formatter-licenses/README.md +12 -0
- package/learn/vendor/manifest.json +1358 -0
- package/learn/vendor/metadata/Browser.Blob.dll +0 -0
- package/learn/vendor/metadata/Browser.Dom.dll +0 -0
- package/learn/vendor/metadata/Browser.Event.dll +0 -0
- package/learn/vendor/metadata/Browser.Gamepad.dll +0 -0
- package/learn/vendor/metadata/Browser.WebGL.dll +0 -0
- package/learn/vendor/metadata/Browser.WebStorage.dll +0 -0
- package/learn/vendor/metadata/FSharp.Core.dll +0 -0
- package/learn/vendor/metadata/Fable.Core.dll +0 -0
- package/learn/vendor/metadata/Fable.Repl.Lib.dll +0 -0
- package/learn/vendor/metadata/System.Collections.Concurrent.dll +0 -0
- package/learn/vendor/metadata/System.Collections.dll +0 -0
- package/learn/vendor/metadata/System.ComponentModel.Primitives.dll +0 -0
- package/learn/vendor/metadata/System.ComponentModel.TypeConverter.dll +0 -0
- package/learn/vendor/metadata/System.ComponentModel.dll +0 -0
- package/learn/vendor/metadata/System.Console.dll +0 -0
- package/learn/vendor/metadata/System.Core.dll +0 -0
- package/learn/vendor/metadata/System.Diagnostics.Debug.dll +0 -0
- package/learn/vendor/metadata/System.Diagnostics.Tools.dll +0 -0
- package/learn/vendor/metadata/System.Diagnostics.Tracing.dll +0 -0
- package/learn/vendor/metadata/System.Globalization.dll +0 -0
- package/learn/vendor/metadata/System.IO.dll +0 -0
- package/learn/vendor/metadata/System.Net.Requests.dll +0 -0
- package/learn/vendor/metadata/System.Net.WebClient.dll +0 -0
- package/learn/vendor/metadata/System.Numerics.dll +0 -0
- package/learn/vendor/metadata/System.Reflection.Extensions.dll +0 -0
- package/learn/vendor/metadata/System.Reflection.Metadata.dll +0 -0
- package/learn/vendor/metadata/System.Reflection.Primitives.dll +0 -0
- package/learn/vendor/metadata/System.Reflection.TypeExtensions.dll +0 -0
- package/learn/vendor/metadata/System.Reflection.dll +0 -0
- package/learn/vendor/metadata/System.Runtime.Extensions.dll +0 -0
- package/learn/vendor/metadata/System.Runtime.InteropServices.dll +0 -0
- package/learn/vendor/metadata/System.Runtime.Numerics.dll +0 -0
- package/learn/vendor/metadata/System.Runtime.dll +0 -0
- package/learn/vendor/metadata/System.Text.Encoding.Extensions.dll +0 -0
- package/learn/vendor/metadata/System.Text.Encoding.dll +0 -0
- package/learn/vendor/metadata/System.Text.RegularExpressions.dll +0 -0
- package/learn/vendor/metadata/System.Threading.Tasks.dll +0 -0
- package/learn/vendor/metadata/System.Threading.Thread.dll +0 -0
- package/learn/vendor/metadata/System.Threading.dll +0 -0
- package/learn/vendor/metadata/System.ValueTuple.dll +0 -0
- package/learn/vendor/metadata/System.dll +0 -0
- package/learn/vendor/metadata/mscorlib.dll +0 -0
- package/learn/vendor/metadata/netstandard.dll +0 -0
- package/learn/vendor/monaco-editor-LICENSE.txt +21 -0
- package/learn/vendor/prettier/babel.mjs +16 -0
- package/learn/vendor/prettier/brace-style.mjs +376 -0
- package/learn/vendor/prettier/estree.mjs +44 -0
- package/learn/vendor/prettier/standalone.mjs +29 -0
- package/learn/vendor/prettier/typescript.mjs +22 -0
- package/learn/vendor/prettier-LICENSE.txt +7 -0
- package/learn/vendor/prettier-plugin-brace-style-LICENSE.txt +21 -0
- package/learn/vendor/typescript-LICENSE.txt +55 -0
- package/learn/vendor/typescript-libs.json +1 -0
- package/learn/vendor/typescript.mjs +451 -0
- package/learn/vendor/zod-LICENSE.txt +21 -0
- package/learn/web-format.mjs +8 -0
- package/learn.mjs +126 -0
- package/lsp.mjs +10 -5
- package/native-evidence.mjs +50 -15
- package/native-examples.mjs +8 -7
- package/native-host.mjs +71 -0
- package/package.json +10 -4
- package/proof.d.ts +8 -2
- package/proof.mjs +183 -31
- package/scala-build-state.mjs +59 -0
- package/templates.mjs +242 -2
- package/test-command.mjs +192 -60
- package/builtin-data-names.mjs +0 -73
- package/examples/native-payments/clojure/lawspec.json +0 -62
- package/examples/native-payments/csharp/lawspec.json +0 -62
- package/examples/native-payments/elixir/lawspec.json +0 -160
- package/examples/native-payments/erlang/lawspec.json +0 -159
- package/examples/native-payments/fsharp/lawspec.json +0 -178
- package/examples/native-payments/gleam/lawspec.json +0 -160
- package/examples/native-payments/go/lawspec.json +0 -147
- package/examples/native-payments/groovy/lawspec.json +0 -176
- package/examples/native-payments/haskell/lawspec.json +0 -160
- package/examples/native-payments/java/lawspec.json +0 -176
- package/examples/native-payments/javascript/lawspec.json +0 -160
- package/examples/native-payments/kotlin/lawspec.json +0 -176
- package/examples/native-payments/prolog/lawspec.json +0 -20
- package/examples/native-payments/python/lawspec.json +0 -160
- package/examples/native-payments/rust/lawspec.json +0 -178
- package/examples/native-payments/scala/lawspec.json +0 -176
- package/examples/native-payments/swift/lawspec.json +0 -165
- package/examples/native-payments/typescript/lawspec.json +0 -160
- package/examples/packages/orders/lawspec.json +0 -27
- package/examples/packages/shop-domain/lawspec-package.json +0 -7
- package/examples/packages/shop-tax-1/lawspec-package.json +0 -5
- package/examples/packages/shop-tax-2/lawspec-package.json +0 -5
- package/explain.mjs +0 -114
- package/expression-presentation.mjs +0 -333
- package/positional-fields.mjs +0 -13
- package/typed-presentation.mjs +0 -165
|
@@ -0,0 +1,2952 @@
|
|
|
1
|
+
{
|
|
2
|
+
"title": "Ask what a passing test really tells you",
|
|
3
|
+
"audience": "Basic variables, functions and conditionals; no functional programming or property-testing experience required.",
|
|
4
|
+
"checkpoint": "Teaching preview: six executable stories redesigned with Winston’s Star. Human review remains open; further course expansion awaits that review.",
|
|
5
|
+
"tracks": [
|
|
6
|
+
{
|
|
7
|
+
"id": "shared",
|
|
8
|
+
"title": "Shared foundations",
|
|
9
|
+
"status": "preview"
|
|
10
|
+
},
|
|
11
|
+
{
|
|
12
|
+
"id": "booking",
|
|
13
|
+
"title": "Event booking",
|
|
14
|
+
"status": "after review",
|
|
15
|
+
"scope": "Capacity, reservations, cancellation and confirmation."
|
|
16
|
+
},
|
|
17
|
+
{
|
|
18
|
+
"id": "library",
|
|
19
|
+
"title": "Library lending",
|
|
20
|
+
"status": "after review",
|
|
21
|
+
"scope": "Loans, returns, holds and overdue behavior."
|
|
22
|
+
},
|
|
23
|
+
{
|
|
24
|
+
"id": "orders",
|
|
25
|
+
"title": "Orders and refunds",
|
|
26
|
+
"status": "after review",
|
|
27
|
+
"scope": "Monetary types, payment states, refund limits and compensation."
|
|
28
|
+
}
|
|
29
|
+
],
|
|
30
|
+
"roadmap": [
|
|
31
|
+
"Properties, property families, generators, shrinking, coverage, replay and reference models.",
|
|
32
|
+
"Domain types, wrappers, records, alternatives, constrained construction, refinements and explicit states.",
|
|
33
|
+
"Typed failures, Result, composition, fail-fast pipelines, accumulated errors, exception boundaries and asynchronous workflows.",
|
|
34
|
+
"Remaining language features, verification layers, dependencies, models, protocols, actors, distribution and tooling."
|
|
35
|
+
],
|
|
36
|
+
"futureAttribution": [
|
|
37
|
+
{
|
|
38
|
+
"title": "Scott Wlaschin — Designing with types: Introduction",
|
|
39
|
+
"url": "https://fsharpforfunandprofit.com/posts/designing-with-types-intro/",
|
|
40
|
+
"use": "Future domain-type lessons; not authored at this checkpoint."
|
|
41
|
+
},
|
|
42
|
+
{
|
|
43
|
+
"title": "Scott Wlaschin — Railway Oriented Programming",
|
|
44
|
+
"url": "https://fsharpforfunandprofit.com/rop/",
|
|
45
|
+
"use": "Future explicit-failure lessons; not authored at this checkpoint."
|
|
46
|
+
},
|
|
47
|
+
{
|
|
48
|
+
"title": "Scott Wlaschin — Against Railway-Oriented Programming",
|
|
49
|
+
"url": "https://fsharpforfunandprofit.com/posts/against-railway-oriented-programming/",
|
|
50
|
+
"use": "Teach Result for expected domain failures, not as a replacement for diagnostics, every exception or every function. Avoid forcing a railway into simple code; distinguish accumulated validation from fail-fast binding."
|
|
51
|
+
}
|
|
52
|
+
],
|
|
53
|
+
"presentationAttribution": [
|
|
54
|
+
{
|
|
55
|
+
"title": "Patrick Henry Winston — Make It Clear",
|
|
56
|
+
"url": "https://mitpress.mit.edu/9780262539388/make-it-clear/"
|
|
57
|
+
},
|
|
58
|
+
{
|
|
59
|
+
"title": "Patrick Henry Winston — How to Speak",
|
|
60
|
+
"url": "https://ocw.mit.edu/courses/15-371-innovation-teams-fall-2024/Unzc731iCUY_transcript.pdf"
|
|
61
|
+
}
|
|
62
|
+
],
|
|
63
|
+
"schemaVersion": 5,
|
|
64
|
+
"version": "preview-4",
|
|
65
|
+
"navigation": [
|
|
66
|
+
{
|
|
67
|
+
"id": "worked",
|
|
68
|
+
"title": "Worked examples",
|
|
69
|
+
"lessons": [
|
|
70
|
+
"wlaschin-add",
|
|
71
|
+
"wlaschin-sort",
|
|
72
|
+
"wlaschin-shrink"
|
|
73
|
+
]
|
|
74
|
+
},
|
|
75
|
+
{
|
|
76
|
+
"id": "practice",
|
|
77
|
+
"title": "Practice",
|
|
78
|
+
"lessons": [
|
|
79
|
+
"examples",
|
|
80
|
+
"weak-properties",
|
|
81
|
+
"shrinking"
|
|
82
|
+
]
|
|
83
|
+
}
|
|
84
|
+
],
|
|
85
|
+
"harnessExplanation": {
|
|
86
|
+
"role": "The Laws tab (Tests.lawspec) says what must be true. Solution implements the function. Harness.lawspec describes how to choose inputs for the generated property checks.",
|
|
87
|
+
"declaration": "The first line names this harness; for names the unit in Laws that it tests. A strategy is a generator: a recipe for drawing inputs. :: introduces its type, where limits its values and any requests generation. for law selects the claim by its full name; use supplies a strategy for one quantified input. A quantified input is a variable introduced by for all.",
|
|
88
|
+
"scope": "A strategy changes the inputs sampled, not the requirement in Laws. A passing sample says only that the checks passed for the inputs tried. It is not a proof, and changing a generator to avoid a failure does not repair a bug or a false claim.",
|
|
89
|
+
"execution": "The generated test runner is also called a harness. You edit the LawSpec configuration here; the compiler builds the runner that calls your implementation and records results. Run checks executes the set shown beneath the button: Examples + boundaries selects concrete and boundary checks; Sampled properties selects generated property cases; All checks includes both. Each step selects its teaching mode; Test controls also offers explicitly named alternate runs. Seed repeats generation under the same code, generator and tool versions; Replay failure also uses the recorded path to the failing case. F# runs through Fable and the JavaScript runner with fast-check in this browser, separately from native .NET/FsCheck."
|
|
90
|
+
},
|
|
91
|
+
"namingGuide": "English phrase names make claims and descriptive helpers readable. Write \"|adding zero keeps the input| with no closing quote. Reuse the full delimited name in for law or a function call. Keep concise code names where they read naturally: add, sort, xs and numbers. Existing short names remain valid, including names in saved drafts.",
|
|
92
|
+
"codeLicenses": [
|
|
93
|
+
{
|
|
94
|
+
"name": "Wlaschin example code (MIT)",
|
|
95
|
+
"source": "https://fsharpforfunandprofit.com/about/license/",
|
|
96
|
+
"text": "Code examples adapted from F# for Fun and Profit.\nCopyright (c) 2012-2021 Scott Wlaschin\nSource and license: https://fsharpforfunandprofit.com/about/license/\n\nPermission is hereby granted, free of charge, to any person obtaining a copy of\nthis software and associated documentation files (the \"Software\"), to deal in\nthe Software without restriction, including without limitation the rights to\nuse, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of\nthe Software, and to permit persons to whom the Software is furnished to do so,\nsubject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in all\ncopies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\nIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\nFITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\nAUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\nLIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\nOUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\nSOFTWARE.\n"
|
|
97
|
+
}
|
|
98
|
+
],
|
|
99
|
+
"lessons": [
|
|
100
|
+
{
|
|
101
|
+
"id": "wlaschin-add",
|
|
102
|
+
"title": "Can tests catch a cheating calculator?",
|
|
103
|
+
"section": "Wlaschin’s examples",
|
|
104
|
+
"vision": "Learn to turn a few calculator examples into requirements that expose different wrong implementations.",
|
|
105
|
+
"slogan": "Which shortcut can still pass?",
|
|
106
|
+
"symbol": "(1, 2) → 3; (2, 2) → ?",
|
|
107
|
+
"explanation": "Laws and generation strategies are authored in LawSpec. Only the implementation changes language.",
|
|
108
|
+
"news": "A property is useful when it rules out a plausible wrong implementation.",
|
|
109
|
+
"contributions": "An addition implementation, two named examples, and separate input-order, repeated-addition and zero-identity requirements. Runs exercise the stated bounded inputs through the browser adapter; they do not prove addition for all integers.",
|
|
110
|
+
"star": {
|
|
111
|
+
"salient": "A property is useful when it rules out a plausible wrong implementation.",
|
|
112
|
+
"slogan": "Which shortcut can still pass?",
|
|
113
|
+
"symbol": "(1, 2) → 3; (2, 2) → ?",
|
|
114
|
+
"surprise": "Multiplication and constant zero can pass relationships that sound like addition.",
|
|
115
|
+
"story": "A calculator keeps memorizing our examples. We try relationships instead, watch new shortcuts pass, then retain the examples and a family of complementary properties."
|
|
116
|
+
},
|
|
117
|
+
"attribution": [
|
|
118
|
+
{
|
|
119
|
+
"title": "Scott Wlaschin — The Enterprise Developer from Hell",
|
|
120
|
+
"url": "https://fsharpforfunandprofit.com/posts/property-based-testing/",
|
|
121
|
+
"use": "Adapted executable addition examples, with original explanatory prose. Browser runs use Fable and fast-check, not the article’s native test framework."
|
|
122
|
+
}
|
|
123
|
+
],
|
|
124
|
+
"hints": [
|
|
125
|
+
"Trace add with the named failing inputs before changing it.",
|
|
126
|
+
"Ask which wrong implementation each property excludes. Keep the concrete examples when adding relationships.",
|
|
127
|
+
"The repair must compute a sum for unfamiliar pairs. Load solution reveals the complete implementation."
|
|
128
|
+
],
|
|
129
|
+
"stages": [
|
|
130
|
+
{
|
|
131
|
+
"id": "one-promise",
|
|
132
|
+
"title": "The calculator knows one answer",
|
|
133
|
+
"story": [
|
|
134
|
+
"We want a calculator that adds two integers. By the end of this lesson, you will be able to explain why a passing test can leave a wrong calculator undetected, and strengthen its checks.",
|
|
135
|
+
"An example is one specified call with an expected answer. A check runs that call and compares the actual answer with the expected one. A passing check means those answers agreed; it does not mean the whole function is correct.",
|
|
136
|
+
"Our first promise is just 1 + 2 = 3. In Solution, add recognizes that pair and returns 3. Every other pair returns 0. Predict what happens on 2 and 2, but keep the test unchanged for this first run.",
|
|
137
|
+
"There are three tabs: Laws states the promises, Solution contains the function, and Harness configures generated test inputs. For now the harness has no strategy: the concrete test already supplies 1 and 2. You can open Harness at any point and expand its explanation below the editor.",
|
|
138
|
+
"Run the example. It checks the one promise we wrote. Ask what evidence we have for the other branch of the function.",
|
|
139
|
+
"The claim’s English name tells us its purpose. Phrase names start with a double quote followed by a pipe (\"|) and finish at the next pipe (|), with no closing quote. add stays short because we call that function repeatedly; the longer claim name should read like a sentence."
|
|
140
|
+
],
|
|
141
|
+
"focus": "Solution",
|
|
142
|
+
"project": "exercises/addition/01",
|
|
143
|
+
"run": {
|
|
144
|
+
"mode": "examples",
|
|
145
|
+
"expect": "passed",
|
|
146
|
+
"seed": 424242
|
|
147
|
+
},
|
|
148
|
+
"action": "Run the example. Explain why the function can pass it while still returning 0 on 2 and 2.",
|
|
149
|
+
"reason": "One successful call establishes one observed answer. Our goal is a function that also handles unfamiliar inputs.",
|
|
150
|
+
"expect": "The supplied code compiles and the selected checks pass. Read which checks actually ran before interpreting this result.",
|
|
151
|
+
"recovery": "Reset this step restores its supplied files and seed. After an edit, use the actual result to judge your version; the story’s prediction describes the supplied files.",
|
|
152
|
+
"syntax": "In Laws, add :: Int32 -> Int32 -> Int32 declares two integer inputs and an integer result. add 1 2 calls the function; = 3 compares the answer with 3. law \"|one plus two is three| names the claim. definition contains the true/false expression to check. A law is a named claim, not an automatically established proof.",
|
|
153
|
+
"editor": "Tests",
|
|
154
|
+
"harnessNotes": [
|
|
155
|
+
"This harness has no strategy yet: this step runs the concrete claims in Laws on their written inputs. An empty harness is not an empty test suite. Later, a quantified law will need generated inputs."
|
|
156
|
+
],
|
|
157
|
+
"symbol": "(1, 2) → 3; (2, 2) → ?",
|
|
158
|
+
"projects": {
|
|
159
|
+
"fsharp": {
|
|
160
|
+
"Solution.fs": "module Solution\n\nlet add (x: int) (y: int) : int = if x = 1 && y = 2 then 3 else 0\n",
|
|
161
|
+
"Tests.lawspec": "-- ref:DEC-learn-tests-in-lawspec\nunit learn.addition\nadd :: Int32 -> Int32 -> Int32\n\nlaw \"|one plus two is three| is\n definition:\n add 1 2 = 3\n end definition\nend law\n\nend unit\n",
|
|
162
|
+
"Harness.lawspec": "harness learn.addition.testing for learn.addition is\n -- This step checks concrete inputs; no generator is selected.\nend harness\n"
|
|
163
|
+
},
|
|
164
|
+
"typescript": {
|
|
165
|
+
"Solution.ts": "export function add(x: number, y: number): number\n{\n return x === 1 && y === 2 ? 3 : 0;\n}\n",
|
|
166
|
+
"Tests.lawspec": "-- ref:DEC-learn-tests-in-lawspec\nunit learn.addition\nadd :: Int32 -> Int32 -> Int32\n\nlaw \"|one plus two is three| is\n definition:\n add 1 2 = 3\n end definition\nend law\n\nend unit\n",
|
|
167
|
+
"Harness.lawspec": "harness learn.addition.testing for learn.addition is\n -- This step checks concrete inputs; no generator is selected.\nend harness\n"
|
|
168
|
+
},
|
|
169
|
+
"javascript": {
|
|
170
|
+
"Solution.js": "export function add(x, y)\n{\n return x === 1 && y === 2 ? 3 : 0;\n}\n",
|
|
171
|
+
"Tests.lawspec": "-- ref:DEC-learn-tests-in-lawspec\nunit learn.addition\nadd :: Int32 -> Int32 -> Int32\n\nlaw \"|one plus two is three| is\n definition:\n add 1 2 = 3\n end definition\nend law\n\nend unit\n",
|
|
172
|
+
"Harness.lawspec": "harness learn.addition.testing for learn.addition is\n -- This step checks concrete inputs; no generator is selected.\nend harness\n"
|
|
173
|
+
}
|
|
174
|
+
},
|
|
175
|
+
"sources": {
|
|
176
|
+
"fsharp": {
|
|
177
|
+
"Tests.lawspec": "exercises/addition/01/Tests.lawspec",
|
|
178
|
+
"Harness.lawspec": "exercises/addition/01/Harness.lawspec",
|
|
179
|
+
"Solution.fs": "exercises/addition/01/fsharp/Solution.fs"
|
|
180
|
+
},
|
|
181
|
+
"typescript": {
|
|
182
|
+
"Tests.lawspec": "exercises/addition/01/Tests.lawspec",
|
|
183
|
+
"Harness.lawspec": "exercises/addition/01/Harness.lawspec",
|
|
184
|
+
"Solution.ts": "exercises/addition/01/typescript/Solution.ts"
|
|
185
|
+
},
|
|
186
|
+
"javascript": {
|
|
187
|
+
"Tests.lawspec": "exercises/addition/01/Tests.lawspec",
|
|
188
|
+
"Harness.lawspec": "exercises/addition/01/Harness.lawspec",
|
|
189
|
+
"Solution.js": "exercises/addition/01/javascript/Solution.js"
|
|
190
|
+
}
|
|
191
|
+
},
|
|
192
|
+
"previousProjects": {
|
|
193
|
+
"fsharp": {
|
|
194
|
+
"Solution.fs": "module Solution\n\nlet add (x: int) (y: int) : int = if x = 1 && y = 2 then 3 else 0\n",
|
|
195
|
+
"Tests.lawspec": "-- ref:DEC-learn-tests-in-lawspec\nunit learn.addition\nadd :: Int32 -> Int32 -> Int32\n\nlaw onePlusTwo is\n definition:\n add 1 2 = 3\n end definition\nend law\n\nend unit\n",
|
|
196
|
+
"Harness.lawspec": "harness learn.addition.testing for learn.addition is\n -- This step checks concrete inputs; no generator is selected.\nend harness\n"
|
|
197
|
+
},
|
|
198
|
+
"typescript": {
|
|
199
|
+
"Solution.ts": "export function add(x: number, y: number): number\n{\n return x === 1 && y === 2 ? 3 : 0;\n}\n",
|
|
200
|
+
"Tests.lawspec": "-- ref:DEC-learn-tests-in-lawspec\nunit learn.addition\nadd :: Int32 -> Int32 -> Int32\n\nlaw onePlusTwo is\n definition:\n add 1 2 = 3\n end definition\nend law\n\nend unit\n",
|
|
201
|
+
"Harness.lawspec": "harness learn.addition.testing for learn.addition is\n -- This step checks concrete inputs; no generator is selected.\nend harness\n"
|
|
202
|
+
},
|
|
203
|
+
"javascript": {
|
|
204
|
+
"Solution.js": "export function add(x, y)\n{\n return x === 1 && y === 2 ? 3 : 0;\n}\n",
|
|
205
|
+
"Tests.lawspec": "-- ref:DEC-learn-tests-in-lawspec\nunit learn.addition\nadd :: Int32 -> Int32 -> Int32\n\nlaw onePlusTwo is\n definition:\n add 1 2 = 3\n end definition\nend law\n\nend unit\n",
|
|
206
|
+
"Harness.lawspec": "harness learn.addition.testing for learn.addition is\n -- This step checks concrete inputs; no generator is selected.\nend harness\n"
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
},
|
|
210
|
+
{
|
|
211
|
+
"id": "second-promise",
|
|
212
|
+
"title": "Ask for an unfamiliar answer",
|
|
213
|
+
"story": [
|
|
214
|
+
"We now ask the same calculator for 2 + 2. Laws has one new law, “two plus two is four”, expecting 4. Solution is unchanged.",
|
|
215
|
+
"Trace the condition in Solution before running: the pair is not 1 and 2, so the function returns 0. Run both examples. “one plus two is three” should pass and “two plus two is four” should fail. The named failure tells us exactly which promise was broken.",
|
|
216
|
+
"Try giving this claim another English phrase name, leaving its definition unchanged. Rerun: a clearer name changes how you find the failure, not the answer the function returns. Reset this step restores the supplied names and code."
|
|
217
|
+
],
|
|
218
|
+
"focus": "Tests",
|
|
219
|
+
"project": "exercises/addition/02",
|
|
220
|
+
"run": {
|
|
221
|
+
"mode": "examples",
|
|
222
|
+
"expect": "failed",
|
|
223
|
+
"failedTests": [
|
|
224
|
+
"learn.addition::|two plus two is four| boundary 1"
|
|
225
|
+
],
|
|
226
|
+
"seed": 424242
|
|
227
|
+
},
|
|
228
|
+
"action": "Run both examples and find “two plus two is four” in Results. Locate the branch that returned its wrong answer.",
|
|
229
|
+
"reason": "The new test exposes behavior that the first example never exercised.",
|
|
230
|
+
"expect": "The supplied code compiles, then the selected checks fail. A compiler error is a different problem; inspect diagnostics if execution did not start.",
|
|
231
|
+
"recovery": "Reset this step restores its supplied files and seed. After an edit, use the actual result to judge your version; the story’s prediction describes the supplied files.",
|
|
232
|
+
"editor": "Solution",
|
|
233
|
+
"syntax": "Two named laws produce separate results. Adding “two plus two is four” changes the test suite; it does not change add.",
|
|
234
|
+
"harnessNotes": [
|
|
235
|
+
"This harness has no strategy yet: this step runs the concrete claims in Laws on their written inputs. An empty harness is not an empty test suite. Later, a quantified law will need generated inputs."
|
|
236
|
+
],
|
|
237
|
+
"projects": {
|
|
238
|
+
"fsharp": {
|
|
239
|
+
"Solution.fs": "module Solution\n\nlet add (x: int) (y: int) : int = if x = 1 && y = 2 then 3 else 0\n",
|
|
240
|
+
"Tests.lawspec": "-- ref:DEC-learn-tests-in-lawspec\nunit learn.addition\nadd :: Int32 -> Int32 -> Int32\n\nlaw \"|one plus two is three| is\n definition:\n add 1 2 = 3\n end definition\nend law\n\nlaw \"|two plus two is four| is\n definition:\n add 2 2 = 4\n end definition\nend law\n\nend unit\n",
|
|
241
|
+
"Harness.lawspec": "harness learn.addition.testing for learn.addition is\n -- This step checks concrete inputs; no generator is selected.\nend harness\n"
|
|
242
|
+
},
|
|
243
|
+
"typescript": {
|
|
244
|
+
"Solution.ts": "export function add(x: number, y: number): number\n{\n return x === 1 && y === 2 ? 3 : 0;\n}\n",
|
|
245
|
+
"Tests.lawspec": "-- ref:DEC-learn-tests-in-lawspec\nunit learn.addition\nadd :: Int32 -> Int32 -> Int32\n\nlaw \"|one plus two is three| is\n definition:\n add 1 2 = 3\n end definition\nend law\n\nlaw \"|two plus two is four| is\n definition:\n add 2 2 = 4\n end definition\nend law\n\nend unit\n",
|
|
246
|
+
"Harness.lawspec": "harness learn.addition.testing for learn.addition is\n -- This step checks concrete inputs; no generator is selected.\nend harness\n"
|
|
247
|
+
},
|
|
248
|
+
"javascript": {
|
|
249
|
+
"Solution.js": "export function add(x, y)\n{\n return x === 1 && y === 2 ? 3 : 0;\n}\n",
|
|
250
|
+
"Tests.lawspec": "-- ref:DEC-learn-tests-in-lawspec\nunit learn.addition\nadd :: Int32 -> Int32 -> Int32\n\nlaw \"|one plus two is three| is\n definition:\n add 1 2 = 3\n end definition\nend law\n\nlaw \"|two plus two is four| is\n definition:\n add 2 2 = 4\n end definition\nend law\n\nend unit\n",
|
|
251
|
+
"Harness.lawspec": "harness learn.addition.testing for learn.addition is\n -- This step checks concrete inputs; no generator is selected.\nend harness\n"
|
|
252
|
+
}
|
|
253
|
+
},
|
|
254
|
+
"sources": {
|
|
255
|
+
"fsharp": {
|
|
256
|
+
"Tests.lawspec": "exercises/addition/02/Tests.lawspec",
|
|
257
|
+
"Harness.lawspec": "exercises/addition/02/Harness.lawspec",
|
|
258
|
+
"Solution.fs": "exercises/addition/01/fsharp/Solution.fs"
|
|
259
|
+
},
|
|
260
|
+
"typescript": {
|
|
261
|
+
"Tests.lawspec": "exercises/addition/02/Tests.lawspec",
|
|
262
|
+
"Harness.lawspec": "exercises/addition/02/Harness.lawspec",
|
|
263
|
+
"Solution.ts": "exercises/addition/01/typescript/Solution.ts"
|
|
264
|
+
},
|
|
265
|
+
"javascript": {
|
|
266
|
+
"Tests.lawspec": "exercises/addition/02/Tests.lawspec",
|
|
267
|
+
"Harness.lawspec": "exercises/addition/02/Harness.lawspec",
|
|
268
|
+
"Solution.js": "exercises/addition/01/javascript/Solution.js"
|
|
269
|
+
}
|
|
270
|
+
},
|
|
271
|
+
"previousProjects": {
|
|
272
|
+
"fsharp": {
|
|
273
|
+
"Solution.fs": "module Solution\n\nlet add (x: int) (y: int) : int = if x = 1 && y = 2 then 3 else 0\n",
|
|
274
|
+
"Tests.lawspec": "-- ref:DEC-learn-tests-in-lawspec\nunit learn.addition\nadd :: Int32 -> Int32 -> Int32\n\nlaw onePlusTwo is\n definition:\n add 1 2 = 3\n end definition\nend law\n\nlaw twoPlusTwo is\n definition:\n add 2 2 = 4\n end definition\nend law\n\nend unit\n",
|
|
275
|
+
"Harness.lawspec": "harness learn.addition.testing for learn.addition is\n -- This step checks concrete inputs; no generator is selected.\nend harness\n"
|
|
276
|
+
},
|
|
277
|
+
"typescript": {
|
|
278
|
+
"Solution.ts": "export function add(x: number, y: number): number\n{\n return x === 1 && y === 2 ? 3 : 0;\n}\n",
|
|
279
|
+
"Tests.lawspec": "-- ref:DEC-learn-tests-in-lawspec\nunit learn.addition\nadd :: Int32 -> Int32 -> Int32\n\nlaw onePlusTwo is\n definition:\n add 1 2 = 3\n end definition\nend law\n\nlaw twoPlusTwo is\n definition:\n add 2 2 = 4\n end definition\nend law\n\nend unit\n",
|
|
280
|
+
"Harness.lawspec": "harness learn.addition.testing for learn.addition is\n -- This step checks concrete inputs; no generator is selected.\nend harness\n"
|
|
281
|
+
},
|
|
282
|
+
"javascript": {
|
|
283
|
+
"Solution.js": "export function add(x, y)\n{\n return x === 1 && y === 2 ? 3 : 0;\n}\n",
|
|
284
|
+
"Tests.lawspec": "-- ref:DEC-learn-tests-in-lawspec\nunit learn.addition\nadd :: Int32 -> Int32 -> Int32\n\nlaw onePlusTwo is\n definition:\n add 1 2 = 3\n end definition\nend law\n\nlaw twoPlusTwo is\n definition:\n add 2 2 = 4\n end definition\nend law\n\nend unit\n",
|
|
285
|
+
"Harness.lawspec": "harness learn.addition.testing for learn.addition is\n -- This step checks concrete inputs; no generator is selected.\nend harness\n"
|
|
286
|
+
}
|
|
287
|
+
}
|
|
288
|
+
},
|
|
289
|
+
{
|
|
290
|
+
"id": "second-shortcut",
|
|
291
|
+
"title": "The calculator memorizes another answer",
|
|
292
|
+
"story": [
|
|
293
|
+
"Solution now has another branch: it recognizes 2 and 2 and returns 4. Our two examples stay unchanged.",
|
|
294
|
+
"Run them. Both pass, but the final branch still returns 0 for unfamiliar pairs. Imagine asking for 2 + 1: it reaches that branch. Adding answers one at a time has not forced the calculator to add.",
|
|
295
|
+
"Next we will compare two calls whose answers should agree, instead of supplying another answer to memorize."
|
|
296
|
+
],
|
|
297
|
+
"focus": "Solution",
|
|
298
|
+
"project": "exercises/addition/03",
|
|
299
|
+
"run": {
|
|
300
|
+
"mode": "examples",
|
|
301
|
+
"expect": "passed",
|
|
302
|
+
"seed": 424242
|
|
303
|
+
},
|
|
304
|
+
"action": "Run the unchanged examples. Then explain why passing them has not repaired the final branch.",
|
|
305
|
+
"reason": "The suite must reject the behavior we care about, rather than merely accumulate successful examples.",
|
|
306
|
+
"expect": "The supplied code compiles and the selected checks pass. Read which checks actually ran before interpreting this result.",
|
|
307
|
+
"recovery": "Reset this step restores its supplied files and seed. After an edit, use the actual result to judge your version; the story’s prediction describes the supplied files.",
|
|
308
|
+
"editor": "Tests",
|
|
309
|
+
"syntax": "Read each condition in Solution as a choice between branches. The tests cover the two recognized pairs; other pairs take the remaining branch.",
|
|
310
|
+
"harnessNotes": [
|
|
311
|
+
"This harness has no strategy yet: this step runs the concrete claims in Laws on their written inputs. An empty harness is not an empty test suite. Later, a quantified law will need generated inputs."
|
|
312
|
+
],
|
|
313
|
+
"projects": {
|
|
314
|
+
"fsharp": {
|
|
315
|
+
"Solution.fs": "module Solution\n\nlet add (x: int) (y: int) : int =\n if x = 1 && y = 2 then 3\n elif x = 2 && y = 2 then 4\n else 0\n",
|
|
316
|
+
"Tests.lawspec": "-- ref:DEC-learn-tests-in-lawspec\nunit learn.addition\nadd :: Int32 -> Int32 -> Int32\n\nlaw \"|one plus two is three| is\n definition:\n add 1 2 = 3\n end definition\nend law\n\nlaw \"|two plus two is four| is\n definition:\n add 2 2 = 4\n end definition\nend law\n\nend unit\n",
|
|
317
|
+
"Harness.lawspec": "harness learn.addition.testing for learn.addition is\n -- This step checks concrete inputs; no generator is selected.\nend harness\n"
|
|
318
|
+
},
|
|
319
|
+
"typescript": {
|
|
320
|
+
"Solution.ts": "export function add(x: number, y: number): number\n{\n return x === 1 && y === 2 ? 3 : x === 2 && y === 2 ? 4 : 0;\n}\n",
|
|
321
|
+
"Tests.lawspec": "-- ref:DEC-learn-tests-in-lawspec\nunit learn.addition\nadd :: Int32 -> Int32 -> Int32\n\nlaw \"|one plus two is three| is\n definition:\n add 1 2 = 3\n end definition\nend law\n\nlaw \"|two plus two is four| is\n definition:\n add 2 2 = 4\n end definition\nend law\n\nend unit\n",
|
|
322
|
+
"Harness.lawspec": "harness learn.addition.testing for learn.addition is\n -- This step checks concrete inputs; no generator is selected.\nend harness\n"
|
|
323
|
+
},
|
|
324
|
+
"javascript": {
|
|
325
|
+
"Solution.js": "export function add(x, y)\n{\n return x === 1 && y === 2 ? 3 : x === 2 && y === 2 ? 4 : 0;\n}\n",
|
|
326
|
+
"Tests.lawspec": "-- ref:DEC-learn-tests-in-lawspec\nunit learn.addition\nadd :: Int32 -> Int32 -> Int32\n\nlaw \"|one plus two is three| is\n definition:\n add 1 2 = 3\n end definition\nend law\n\nlaw \"|two plus two is four| is\n definition:\n add 2 2 = 4\n end definition\nend law\n\nend unit\n",
|
|
327
|
+
"Harness.lawspec": "harness learn.addition.testing for learn.addition is\n -- This step checks concrete inputs; no generator is selected.\nend harness\n"
|
|
328
|
+
}
|
|
329
|
+
},
|
|
330
|
+
"sources": {
|
|
331
|
+
"fsharp": {
|
|
332
|
+
"Tests.lawspec": "exercises/addition/03/Tests.lawspec",
|
|
333
|
+
"Harness.lawspec": "exercises/addition/03/Harness.lawspec",
|
|
334
|
+
"Solution.fs": "exercises/addition/03/fsharp/Solution.fs"
|
|
335
|
+
},
|
|
336
|
+
"typescript": {
|
|
337
|
+
"Tests.lawspec": "exercises/addition/03/Tests.lawspec",
|
|
338
|
+
"Harness.lawspec": "exercises/addition/03/Harness.lawspec",
|
|
339
|
+
"Solution.ts": "exercises/addition/03/typescript/Solution.ts"
|
|
340
|
+
},
|
|
341
|
+
"javascript": {
|
|
342
|
+
"Tests.lawspec": "exercises/addition/03/Tests.lawspec",
|
|
343
|
+
"Harness.lawspec": "exercises/addition/03/Harness.lawspec",
|
|
344
|
+
"Solution.js": "exercises/addition/03/javascript/Solution.js"
|
|
345
|
+
}
|
|
346
|
+
},
|
|
347
|
+
"previousProjects": {
|
|
348
|
+
"fsharp": {
|
|
349
|
+
"Solution.fs": "module Solution\n\nlet add (x: int) (y: int) : int =\n if x = 1 && y = 2 then 3\n elif x = 2 && y = 2 then 4\n else 0\n",
|
|
350
|
+
"Tests.lawspec": "-- ref:DEC-learn-tests-in-lawspec\nunit learn.addition\nadd :: Int32 -> Int32 -> Int32\n\nlaw onePlusTwo is\n definition:\n add 1 2 = 3\n end definition\nend law\n\nlaw twoPlusTwo is\n definition:\n add 2 2 = 4\n end definition\nend law\n\nend unit\n",
|
|
351
|
+
"Harness.lawspec": "harness learn.addition.testing for learn.addition is\n -- This step checks concrete inputs; no generator is selected.\nend harness\n"
|
|
352
|
+
},
|
|
353
|
+
"typescript": {
|
|
354
|
+
"Solution.ts": "export function add(x: number, y: number): number\n{\n return x === 1 && y === 2 ? 3 : x === 2 && y === 2 ? 4 : 0;\n}\n",
|
|
355
|
+
"Tests.lawspec": "-- ref:DEC-learn-tests-in-lawspec\nunit learn.addition\nadd :: Int32 -> Int32 -> Int32\n\nlaw onePlusTwo is\n definition:\n add 1 2 = 3\n end definition\nend law\n\nlaw twoPlusTwo is\n definition:\n add 2 2 = 4\n end definition\nend law\n\nend unit\n",
|
|
356
|
+
"Harness.lawspec": "harness learn.addition.testing for learn.addition is\n -- This step checks concrete inputs; no generator is selected.\nend harness\n"
|
|
357
|
+
},
|
|
358
|
+
"javascript": {
|
|
359
|
+
"Solution.js": "export function add(x, y)\n{\n return x === 1 && y === 2 ? 3 : x === 2 && y === 2 ? 4 : 0;\n}\n",
|
|
360
|
+
"Tests.lawspec": "-- ref:DEC-learn-tests-in-lawspec\nunit learn.addition\nadd :: Int32 -> Int32 -> Int32\n\nlaw onePlusTwo is\n definition:\n add 1 2 = 3\n end definition\nend law\n\nlaw twoPlusTwo is\n definition:\n add 2 2 = 4\n end definition\nend law\n\nend unit\n",
|
|
361
|
+
"Harness.lawspec": "harness learn.addition.testing for learn.addition is\n -- This step checks concrete inputs; no generator is selected.\nend harness\n"
|
|
362
|
+
}
|
|
363
|
+
}
|
|
364
|
+
},
|
|
365
|
+
{
|
|
366
|
+
"id": "swap",
|
|
367
|
+
"title": "Compare a call with its reversed call",
|
|
368
|
+
"story": [
|
|
369
|
+
"An example supplies one particular input. A property states a rule for a range of inputs. Property-based testing generates inputs and checks that rule on each one. Here we will compare two calls instead of listing the expected sum for each pair.",
|
|
370
|
+
"For addition, swapping the two inputs should leave the answer unchanged. Laws names this relationship “swapping the inputs keeps the answer”: it compares add x y with add y x.",
|
|
371
|
+
"Where do x and y come from? Open Harness. A harness connects a law to a strategy: a recipe for test data. Here numbers chooses integers from -2 through 2. The two use lines feed separate draws into x and y of “swapping the inputs keeps the answer”. Laws supplies the comparison; the harness supplies its inputs.",
|
|
372
|
+
"Our calculator remembers 1 + 2 but not 2 + 1. Use Run checks with All checks and inspect the sampled failure. A relationship has exposed an answer we never listed as a concrete test."
|
|
373
|
+
],
|
|
374
|
+
"focus": "Tests",
|
|
375
|
+
"project": "exercises/addition/04",
|
|
376
|
+
"run": {
|
|
377
|
+
"mode": "all",
|
|
378
|
+
"expect": "failed",
|
|
379
|
+
"sampled": "failed",
|
|
380
|
+
"seed": 424242
|
|
381
|
+
},
|
|
382
|
+
"action": "Use Run checks with All checks. Use the reported inputs to trace both calls to add, and explain why their results differ.",
|
|
383
|
+
"reason": "This property can reject an implementation that memorizes particular input orders.",
|
|
384
|
+
"expect": "The supplied code compiles, then the selected checks fail. A compiler error is a different problem; inspect diagnostics if execution did not start.",
|
|
385
|
+
"recovery": "Reset this step restores its supplied files and seed. After an edit, use the actual result to judge your version; the story’s prediction describes the supplied files.",
|
|
386
|
+
"syntax": "for all states the inputs covered by the claim. The harness’s for law reference repeats the same phrase name from Laws, including its \"| and | delimiters. use supplies a strategy for each input. :: introduces its type, where gives bounds and any requests generated values. This recipe samples -2 through 2 even though the law’s stated domain is -10 through 10.",
|
|
387
|
+
"editor": "Solution",
|
|
388
|
+
"harnessNotes": [
|
|
389
|
+
"numbers draws Int32 integers from -2 through 2, including both endpoints. The variable n describes each candidate value inside the strategy; it is not a separate input to add.",
|
|
390
|
+
"The binding for “swapping the inputs keeps the answer” selects the claim in Laws. use numbers for x and use numbers for y draw the two inputs separately from that recipe. The law permits -10 through 10; this strategy samples a smaller region, so a passing sample cannot establish the whole claim."
|
|
391
|
+
],
|
|
392
|
+
"projects": {
|
|
393
|
+
"fsharp": {
|
|
394
|
+
"Solution.fs": "module Solution\n\nlet add (x: int) (y: int) : int =\n if x = 1 && y = 2 then 3\n elif x = 2 && y = 2 then 4\n else 0\n",
|
|
395
|
+
"Tests.lawspec": "-- ref:DEC-learn-tests-in-lawspec\nunit learn.addition\nadd :: Int32 -> Int32 -> Int32\n\nlaw \"|one plus two is three| is\n definition:\n add 1 2 = 3\n end definition\nend law\n\nlaw \"|two plus two is four| is\n definition:\n add 2 2 = 4\n end definition\nend law\n\nlaw \"|swapping the inputs keeps the answer| is\n definition:\n for all\n (x :: Int32 where x >= -10 and x <= 10)\n (y :: Int32 where y >= -10 and y <= 10)\n =>\n add x y = add y x\n end for all\n end definition\nend law\n\nend unit\n",
|
|
396
|
+
"Harness.lawspec": "harness learn.addition.testing for learn.addition is\n strategy numbers :: (n :: Int32 where n >= -2 and n <= 2) is any end strategy\n for law \"|swapping the inputs keeps the answer|\n use numbers for x\n use numbers for y\n end for law\nend harness\n"
|
|
397
|
+
},
|
|
398
|
+
"typescript": {
|
|
399
|
+
"Solution.ts": "export function add(x: number, y: number): number\n{\n return x === 1 && y === 2 ? 3 : x === 2 && y === 2 ? 4 : 0;\n}\n",
|
|
400
|
+
"Tests.lawspec": "-- ref:DEC-learn-tests-in-lawspec\nunit learn.addition\nadd :: Int32 -> Int32 -> Int32\n\nlaw \"|one plus two is three| is\n definition:\n add 1 2 = 3\n end definition\nend law\n\nlaw \"|two plus two is four| is\n definition:\n add 2 2 = 4\n end definition\nend law\n\nlaw \"|swapping the inputs keeps the answer| is\n definition:\n for all\n (x :: Int32 where x >= -10 and x <= 10)\n (y :: Int32 where y >= -10 and y <= 10)\n =>\n add x y = add y x\n end for all\n end definition\nend law\n\nend unit\n",
|
|
401
|
+
"Harness.lawspec": "harness learn.addition.testing for learn.addition is\n strategy numbers :: (n :: Int32 where n >= -2 and n <= 2) is any end strategy\n for law \"|swapping the inputs keeps the answer|\n use numbers for x\n use numbers for y\n end for law\nend harness\n"
|
|
402
|
+
},
|
|
403
|
+
"javascript": {
|
|
404
|
+
"Solution.js": "export function add(x, y)\n{\n return x === 1 && y === 2 ? 3 : x === 2 && y === 2 ? 4 : 0;\n}\n",
|
|
405
|
+
"Tests.lawspec": "-- ref:DEC-learn-tests-in-lawspec\nunit learn.addition\nadd :: Int32 -> Int32 -> Int32\n\nlaw \"|one plus two is three| is\n definition:\n add 1 2 = 3\n end definition\nend law\n\nlaw \"|two plus two is four| is\n definition:\n add 2 2 = 4\n end definition\nend law\n\nlaw \"|swapping the inputs keeps the answer| is\n definition:\n for all\n (x :: Int32 where x >= -10 and x <= 10)\n (y :: Int32 where y >= -10 and y <= 10)\n =>\n add x y = add y x\n end for all\n end definition\nend law\n\nend unit\n",
|
|
406
|
+
"Harness.lawspec": "harness learn.addition.testing for learn.addition is\n strategy numbers :: (n :: Int32 where n >= -2 and n <= 2) is any end strategy\n for law \"|swapping the inputs keeps the answer|\n use numbers for x\n use numbers for y\n end for law\nend harness\n"
|
|
407
|
+
}
|
|
408
|
+
},
|
|
409
|
+
"sources": {
|
|
410
|
+
"fsharp": {
|
|
411
|
+
"Tests.lawspec": "exercises/addition/04/Tests.lawspec",
|
|
412
|
+
"Harness.lawspec": "exercises/addition/04/Harness.lawspec",
|
|
413
|
+
"Solution.fs": "exercises/addition/03/fsharp/Solution.fs"
|
|
414
|
+
},
|
|
415
|
+
"typescript": {
|
|
416
|
+
"Tests.lawspec": "exercises/addition/04/Tests.lawspec",
|
|
417
|
+
"Harness.lawspec": "exercises/addition/04/Harness.lawspec",
|
|
418
|
+
"Solution.ts": "exercises/addition/03/typescript/Solution.ts"
|
|
419
|
+
},
|
|
420
|
+
"javascript": {
|
|
421
|
+
"Tests.lawspec": "exercises/addition/04/Tests.lawspec",
|
|
422
|
+
"Harness.lawspec": "exercises/addition/04/Harness.lawspec",
|
|
423
|
+
"Solution.js": "exercises/addition/03/javascript/Solution.js"
|
|
424
|
+
}
|
|
425
|
+
},
|
|
426
|
+
"previousProjects": {
|
|
427
|
+
"fsharp": {
|
|
428
|
+
"Solution.fs": "module Solution\n\nlet add (x: int) (y: int) : int =\n if x = 1 && y = 2 then 3\n elif x = 2 && y = 2 then 4\n else 0\n",
|
|
429
|
+
"Tests.lawspec": "-- ref:DEC-learn-tests-in-lawspec\nunit learn.addition\nadd :: Int32 -> Int32 -> Int32\n\nlaw onePlusTwo is\n definition:\n add 1 2 = 3\n end definition\nend law\n\nlaw twoPlusTwo is\n definition:\n add 2 2 = 4\n end definition\nend law\n\nlaw swapInputs is\n definition:\n for all (x :: Int32 where x >= -10 and x <= 10) (y :: Int32 where y >= -10\n and y <= 10) => add x y = add y x end for all\n end definition\nend law\n\nend unit\n",
|
|
430
|
+
"Harness.lawspec": "harness learn.addition.testing for learn.addition is\n strategy numbers :: (n :: Int32 where n >= -2 and n <= 2) is any end strategy\n for law swapInputs\n use numbers for x\n use numbers for y\n end for law\nend harness\n"
|
|
431
|
+
},
|
|
432
|
+
"typescript": {
|
|
433
|
+
"Solution.ts": "export function add(x: number, y: number): number\n{\n return x === 1 && y === 2 ? 3 : x === 2 && y === 2 ? 4 : 0;\n}\n",
|
|
434
|
+
"Tests.lawspec": "-- ref:DEC-learn-tests-in-lawspec\nunit learn.addition\nadd :: Int32 -> Int32 -> Int32\n\nlaw onePlusTwo is\n definition:\n add 1 2 = 3\n end definition\nend law\n\nlaw twoPlusTwo is\n definition:\n add 2 2 = 4\n end definition\nend law\n\nlaw swapInputs is\n definition:\n for all (x :: Int32 where x >= -10 and x <= 10) (y :: Int32 where y >= -10\n and y <= 10) => add x y = add y x end for all\n end definition\nend law\n\nend unit\n",
|
|
435
|
+
"Harness.lawspec": "harness learn.addition.testing for learn.addition is\n strategy numbers :: (n :: Int32 where n >= -2 and n <= 2) is any end strategy\n for law swapInputs\n use numbers for x\n use numbers for y\n end for law\nend harness\n"
|
|
436
|
+
},
|
|
437
|
+
"javascript": {
|
|
438
|
+
"Solution.js": "export function add(x, y)\n{\n return x === 1 && y === 2 ? 3 : x === 2 && y === 2 ? 4 : 0;\n}\n",
|
|
439
|
+
"Tests.lawspec": "-- ref:DEC-learn-tests-in-lawspec\nunit learn.addition\nadd :: Int32 -> Int32 -> Int32\n\nlaw onePlusTwo is\n definition:\n add 1 2 = 3\n end definition\nend law\n\nlaw twoPlusTwo is\n definition:\n add 2 2 = 4\n end definition\nend law\n\nlaw swapInputs is\n definition:\n for all (x :: Int32 where x >= -10 and x <= 10) (y :: Int32 where y >= -10\n and y <= 10) => add x y = add y x end for all\n end definition\nend law\n\nend unit\n",
|
|
440
|
+
"Harness.lawspec": "harness learn.addition.testing for learn.addition is\n strategy numbers :: (n :: Int32 where n >= -2 and n <= 2) is any end strategy\n for law swapInputs\n use numbers for x\n use numbers for y\n end for law\nend harness\n"
|
|
441
|
+
}
|
|
442
|
+
}
|
|
443
|
+
},
|
|
444
|
+
{
|
|
445
|
+
"id": "multiply",
|
|
446
|
+
"title": "Multiplication finds an escape route",
|
|
447
|
+
"story": [
|
|
448
|
+
"The new calculator multiplies its two inputs. Predict whether reversing the inputs changes its answer.",
|
|
449
|
+
"This step runs only the sampled property. Multiplication passes “swapping the inputs keeps the answer” because x times y equals y times x. The addition examples would reject this implementation; they are still in Laws but are not selected by this run.",
|
|
450
|
+
"A property can be true of the wrong operation. Keep the examples and look for another relationship that distinguishes addition from multiplication.",
|
|
451
|
+
"The scope caption under Run checks says Sampled properties. In Results, generated trials counts the inputs tried for each property; it is different from the number of named properties. Open Test controls if you want a separate run of the concrete examples."
|
|
452
|
+
],
|
|
453
|
+
"focus": "Solution",
|
|
454
|
+
"project": "exercises/addition/05",
|
|
455
|
+
"run": {
|
|
456
|
+
"mode": "sample",
|
|
457
|
+
"expect": "passed",
|
|
458
|
+
"sampled": "passed",
|
|
459
|
+
"seed": 424242
|
|
460
|
+
},
|
|
461
|
+
"action": "Run the sampled property. Explain why its pass is compatible with a wrong answer for 1 + 2.",
|
|
462
|
+
"reason": "The meaning of a pass depends on the requirement checked and the checks selected.",
|
|
463
|
+
"expect": "The supplied code compiles and the selected checks pass. Read which checks actually ran before interpreting this result.",
|
|
464
|
+
"recovery": "Reset this step restores its supplied files and seed. After an edit, use the actual result to judge your version; the story’s prediction describes the supplied files.",
|
|
465
|
+
"editor": "Tests",
|
|
466
|
+
"syntax": "“swapping the inputs keeps the answer” compares two results; it never states an expected sum. The Sampled property mode omits the named concrete examples.",
|
|
467
|
+
"harnessNotes": [
|
|
468
|
+
"numbers draws Int32 integers from -2 through 2, including both endpoints. The variable n describes each candidate value inside the strategy; it is not a separate input to add.",
|
|
469
|
+
"The binding for “swapping the inputs keeps the answer” selects the claim in Laws. use numbers for x and use numbers for y draw the two inputs separately from that recipe. The law permits -10 through 10; this strategy samples a smaller region, so a passing sample cannot establish the whole claim."
|
|
470
|
+
],
|
|
471
|
+
"projects": {
|
|
472
|
+
"fsharp": {
|
|
473
|
+
"Solution.fs": "module Solution\n\nlet add (x: int) (y: int) : int = x * y\n",
|
|
474
|
+
"Tests.lawspec": "-- ref:DEC-learn-tests-in-lawspec\nunit learn.addition\nadd :: Int32 -> Int32 -> Int32\n\nlaw \"|one plus two is three| is\n definition:\n add 1 2 = 3\n end definition\nend law\n\nlaw \"|two plus two is four| is\n definition:\n add 2 2 = 4\n end definition\nend law\n\nlaw \"|swapping the inputs keeps the answer| is\n definition:\n for all\n (x :: Int32 where x >= -10 and x <= 10)\n (y :: Int32 where y >= -10 and y <= 10)\n =>\n add x y = add y x\n end for all\n end definition\nend law\n\nend unit\n",
|
|
475
|
+
"Harness.lawspec": "harness learn.addition.testing for learn.addition is\n strategy numbers :: (n :: Int32 where n >= -2 and n <= 2) is any end strategy\n for law \"|swapping the inputs keeps the answer|\n use numbers for x\n use numbers for y\n end for law\nend harness\n"
|
|
476
|
+
},
|
|
477
|
+
"typescript": {
|
|
478
|
+
"Solution.ts": "export function add(x: number, y: number): number\n{\n return x * y;\n}\n",
|
|
479
|
+
"Tests.lawspec": "-- ref:DEC-learn-tests-in-lawspec\nunit learn.addition\nadd :: Int32 -> Int32 -> Int32\n\nlaw \"|one plus two is three| is\n definition:\n add 1 2 = 3\n end definition\nend law\n\nlaw \"|two plus two is four| is\n definition:\n add 2 2 = 4\n end definition\nend law\n\nlaw \"|swapping the inputs keeps the answer| is\n definition:\n for all\n (x :: Int32 where x >= -10 and x <= 10)\n (y :: Int32 where y >= -10 and y <= 10)\n =>\n add x y = add y x\n end for all\n end definition\nend law\n\nend unit\n",
|
|
480
|
+
"Harness.lawspec": "harness learn.addition.testing for learn.addition is\n strategy numbers :: (n :: Int32 where n >= -2 and n <= 2) is any end strategy\n for law \"|swapping the inputs keeps the answer|\n use numbers for x\n use numbers for y\n end for law\nend harness\n"
|
|
481
|
+
},
|
|
482
|
+
"javascript": {
|
|
483
|
+
"Solution.js": "export function add(x, y)\n{\n return x * y;\n}\n",
|
|
484
|
+
"Tests.lawspec": "-- ref:DEC-learn-tests-in-lawspec\nunit learn.addition\nadd :: Int32 -> Int32 -> Int32\n\nlaw \"|one plus two is three| is\n definition:\n add 1 2 = 3\n end definition\nend law\n\nlaw \"|two plus two is four| is\n definition:\n add 2 2 = 4\n end definition\nend law\n\nlaw \"|swapping the inputs keeps the answer| is\n definition:\n for all\n (x :: Int32 where x >= -10 and x <= 10)\n (y :: Int32 where y >= -10 and y <= 10)\n =>\n add x y = add y x\n end for all\n end definition\nend law\n\nend unit\n",
|
|
485
|
+
"Harness.lawspec": "harness learn.addition.testing for learn.addition is\n strategy numbers :: (n :: Int32 where n >= -2 and n <= 2) is any end strategy\n for law \"|swapping the inputs keeps the answer|\n use numbers for x\n use numbers for y\n end for law\nend harness\n"
|
|
486
|
+
}
|
|
487
|
+
},
|
|
488
|
+
"sources": {
|
|
489
|
+
"fsharp": {
|
|
490
|
+
"Tests.lawspec": "exercises/addition/05/Tests.lawspec",
|
|
491
|
+
"Harness.lawspec": "exercises/addition/05/Harness.lawspec",
|
|
492
|
+
"Solution.fs": "exercises/addition/05/fsharp/Solution.fs"
|
|
493
|
+
},
|
|
494
|
+
"typescript": {
|
|
495
|
+
"Tests.lawspec": "exercises/addition/05/Tests.lawspec",
|
|
496
|
+
"Harness.lawspec": "exercises/addition/05/Harness.lawspec",
|
|
497
|
+
"Solution.ts": "exercises/addition/05/typescript/Solution.ts"
|
|
498
|
+
},
|
|
499
|
+
"javascript": {
|
|
500
|
+
"Tests.lawspec": "exercises/addition/05/Tests.lawspec",
|
|
501
|
+
"Harness.lawspec": "exercises/addition/05/Harness.lawspec",
|
|
502
|
+
"Solution.js": "exercises/addition/05/javascript/Solution.js"
|
|
503
|
+
}
|
|
504
|
+
},
|
|
505
|
+
"previousProjects": {
|
|
506
|
+
"fsharp": {
|
|
507
|
+
"Solution.fs": "module Solution\n\nlet add (x: int) (y: int) : int = x * y\n",
|
|
508
|
+
"Tests.lawspec": "-- ref:DEC-learn-tests-in-lawspec\nunit learn.addition\nadd :: Int32 -> Int32 -> Int32\n\nlaw onePlusTwo is\n definition:\n add 1 2 = 3\n end definition\nend law\n\nlaw twoPlusTwo is\n definition:\n add 2 2 = 4\n end definition\nend law\n\nlaw swapInputs is\n definition:\n for all (x :: Int32 where x >= -10 and x <= 10) (y :: Int32 where y >= -10\n and y <= 10) => add x y = add y x end for all\n end definition\nend law\n\nend unit\n",
|
|
509
|
+
"Harness.lawspec": "harness learn.addition.testing for learn.addition is\n strategy numbers :: (n :: Int32 where n >= -2 and n <= 2) is any end strategy\n for law swapInputs\n use numbers for x\n use numbers for y\n end for law\nend harness\n"
|
|
510
|
+
},
|
|
511
|
+
"typescript": {
|
|
512
|
+
"Solution.ts": "export function add(x: number, y: number): number\n{\n return x * y;\n}\n",
|
|
513
|
+
"Tests.lawspec": "-- ref:DEC-learn-tests-in-lawspec\nunit learn.addition\nadd :: Int32 -> Int32 -> Int32\n\nlaw onePlusTwo is\n definition:\n add 1 2 = 3\n end definition\nend law\n\nlaw twoPlusTwo is\n definition:\n add 2 2 = 4\n end definition\nend law\n\nlaw swapInputs is\n definition:\n for all (x :: Int32 where x >= -10 and x <= 10) (y :: Int32 where y >= -10\n and y <= 10) => add x y = add y x end for all\n end definition\nend law\n\nend unit\n",
|
|
514
|
+
"Harness.lawspec": "harness learn.addition.testing for learn.addition is\n strategy numbers :: (n :: Int32 where n >= -2 and n <= 2) is any end strategy\n for law swapInputs\n use numbers for x\n use numbers for y\n end for law\nend harness\n"
|
|
515
|
+
},
|
|
516
|
+
"javascript": {
|
|
517
|
+
"Solution.js": "export function add(x, y)\n{\n return x * y;\n}\n",
|
|
518
|
+
"Tests.lawspec": "-- ref:DEC-learn-tests-in-lawspec\nunit learn.addition\nadd :: Int32 -> Int32 -> Int32\n\nlaw onePlusTwo is\n definition:\n add 1 2 = 3\n end definition\nend law\n\nlaw twoPlusTwo is\n definition:\n add 2 2 = 4\n end definition\nend law\n\nlaw swapInputs is\n definition:\n for all (x :: Int32 where x >= -10 and x <= 10) (y :: Int32 where y >= -10\n and y <= 10) => add x y = add y x end for all\n end definition\nend law\n\nend unit\n",
|
|
519
|
+
"Harness.lawspec": "harness learn.addition.testing for learn.addition is\n strategy numbers :: (n :: Int32 where n >= -2 and n <= 2) is any end strategy\n for law swapInputs\n use numbers for x\n use numbers for y\n end for law\nend harness\n"
|
|
520
|
+
}
|
|
521
|
+
}
|
|
522
|
+
},
|
|
523
|
+
{
|
|
524
|
+
"id": "repeat",
|
|
525
|
+
"title": "Add one twice, or add two once",
|
|
526
|
+
"story": [
|
|
527
|
+
"For addition, adding one and then one again should agree with adding two once. The new “adding one twice agrees with adding two” law states that relationship. “swapping the inputs keeps the answer” remains.",
|
|
528
|
+
"Solution still multiplies. Trace the new law with x equal to 2: multiplying by one twice leaves 2, while multiplying by two produces 4. Run the sampled properties and inspect which law fails."
|
|
529
|
+
],
|
|
530
|
+
"focus": "Tests",
|
|
531
|
+
"project": "exercises/addition/06",
|
|
532
|
+
"run": {
|
|
533
|
+
"mode": "sample",
|
|
534
|
+
"expect": "failed",
|
|
535
|
+
"sampled": "failed",
|
|
536
|
+
"seed": 424242
|
|
537
|
+
},
|
|
538
|
+
"action": "Run the sampled properties. Explain why “adding one twice agrees with adding two” rejects multiplication even though “swapping the inputs keeps the answer” accepts it.",
|
|
539
|
+
"reason": "Each retained property should rule out a different escape route.",
|
|
540
|
+
"expect": "The supplied code compiles, then the selected checks fail. A compiler error is a different problem; inspect diagnostics if execution did not start.",
|
|
541
|
+
"recovery": "Reset this step restores its supplied files and seed. After an edit, use the actual result to judge your version; the story’s prediction describes the supplied files.",
|
|
542
|
+
"editor": "Solution",
|
|
543
|
+
"syntax": "add 1 (add 1 x) evaluates the inner call first, then passes its result to the outer call. add 2 x is the other path. The harness supplies x; the constants 1 and 2 are written in the law.",
|
|
544
|
+
"harnessNotes": [
|
|
545
|
+
"numbers draws Int32 integers from -2 through 2, including both endpoints. The variable n describes each candidate value inside the strategy; it is not a separate input to add.",
|
|
546
|
+
"The binding for “swapping the inputs keeps the answer” selects the claim in Laws. use numbers for x and use numbers for y draw the two inputs separately from that recipe. The law permits -10 through 10; this strategy samples a smaller region, so a passing sample cannot establish the whole claim.",
|
|
547
|
+
"The “adding one twice agrees with adding two” binding supplies x from numbers as well. The constants one and two are written in the law; they do not need their own strategies."
|
|
548
|
+
],
|
|
549
|
+
"projects": {
|
|
550
|
+
"fsharp": {
|
|
551
|
+
"Solution.fs": "module Solution\n\nlet add (x: int) (y: int) : int = x * y\n",
|
|
552
|
+
"Tests.lawspec": "-- ref:DEC-learn-tests-in-lawspec\nunit learn.addition\nadd :: Int32 -> Int32 -> Int32\n\nlaw \"|one plus two is three| is\n definition:\n add 1 2 = 3\n end definition\nend law\n\nlaw \"|two plus two is four| is\n definition:\n add 2 2 = 4\n end definition\nend law\n\nlaw \"|swapping the inputs keeps the answer| is\n definition:\n for all\n (x :: Int32 where x >= -10 and x <= 10)\n (y :: Int32 where y >= -10 and y <= 10)\n =>\n add x y = add y x\n end for all\n end definition\nend law\n\nlaw \"|adding one twice agrees with adding two| is\n definition:\n for all (x :: Int32 where x >= -10 and x <= 10) =>\n add 1 (add 1 x) = add 2 x\n end for all\n end definition\nend law\n\nend unit\n",
|
|
553
|
+
"Harness.lawspec": "harness learn.addition.testing for learn.addition is\n strategy numbers :: (n :: Int32 where n >= -2 and n <= 2) is any end strategy\n for law \"|swapping the inputs keeps the answer|\n use numbers for x\n use numbers for y\n end for law\n for law \"|adding one twice agrees with adding two|\n use numbers for x\n end for law\nend harness\n"
|
|
554
|
+
},
|
|
555
|
+
"typescript": {
|
|
556
|
+
"Solution.ts": "export function add(x: number, y: number): number\n{\n return x * y;\n}\n",
|
|
557
|
+
"Tests.lawspec": "-- ref:DEC-learn-tests-in-lawspec\nunit learn.addition\nadd :: Int32 -> Int32 -> Int32\n\nlaw \"|one plus two is three| is\n definition:\n add 1 2 = 3\n end definition\nend law\n\nlaw \"|two plus two is four| is\n definition:\n add 2 2 = 4\n end definition\nend law\n\nlaw \"|swapping the inputs keeps the answer| is\n definition:\n for all\n (x :: Int32 where x >= -10 and x <= 10)\n (y :: Int32 where y >= -10 and y <= 10)\n =>\n add x y = add y x\n end for all\n end definition\nend law\n\nlaw \"|adding one twice agrees with adding two| is\n definition:\n for all (x :: Int32 where x >= -10 and x <= 10) =>\n add 1 (add 1 x) = add 2 x\n end for all\n end definition\nend law\n\nend unit\n",
|
|
558
|
+
"Harness.lawspec": "harness learn.addition.testing for learn.addition is\n strategy numbers :: (n :: Int32 where n >= -2 and n <= 2) is any end strategy\n for law \"|swapping the inputs keeps the answer|\n use numbers for x\n use numbers for y\n end for law\n for law \"|adding one twice agrees with adding two|\n use numbers for x\n end for law\nend harness\n"
|
|
559
|
+
},
|
|
560
|
+
"javascript": {
|
|
561
|
+
"Solution.js": "export function add(x, y)\n{\n return x * y;\n}\n",
|
|
562
|
+
"Tests.lawspec": "-- ref:DEC-learn-tests-in-lawspec\nunit learn.addition\nadd :: Int32 -> Int32 -> Int32\n\nlaw \"|one plus two is three| is\n definition:\n add 1 2 = 3\n end definition\nend law\n\nlaw \"|two plus two is four| is\n definition:\n add 2 2 = 4\n end definition\nend law\n\nlaw \"|swapping the inputs keeps the answer| is\n definition:\n for all\n (x :: Int32 where x >= -10 and x <= 10)\n (y :: Int32 where y >= -10 and y <= 10)\n =>\n add x y = add y x\n end for all\n end definition\nend law\n\nlaw \"|adding one twice agrees with adding two| is\n definition:\n for all (x :: Int32 where x >= -10 and x <= 10) =>\n add 1 (add 1 x) = add 2 x\n end for all\n end definition\nend law\n\nend unit\n",
|
|
563
|
+
"Harness.lawspec": "harness learn.addition.testing for learn.addition is\n strategy numbers :: (n :: Int32 where n >= -2 and n <= 2) is any end strategy\n for law \"|swapping the inputs keeps the answer|\n use numbers for x\n use numbers for y\n end for law\n for law \"|adding one twice agrees with adding two|\n use numbers for x\n end for law\nend harness\n"
|
|
564
|
+
}
|
|
565
|
+
},
|
|
566
|
+
"sources": {
|
|
567
|
+
"fsharp": {
|
|
568
|
+
"Tests.lawspec": "exercises/addition/06/Tests.lawspec",
|
|
569
|
+
"Harness.lawspec": "exercises/addition/06/Harness.lawspec",
|
|
570
|
+
"Solution.fs": "exercises/addition/05/fsharp/Solution.fs"
|
|
571
|
+
},
|
|
572
|
+
"typescript": {
|
|
573
|
+
"Tests.lawspec": "exercises/addition/06/Tests.lawspec",
|
|
574
|
+
"Harness.lawspec": "exercises/addition/06/Harness.lawspec",
|
|
575
|
+
"Solution.ts": "exercises/addition/05/typescript/Solution.ts"
|
|
576
|
+
},
|
|
577
|
+
"javascript": {
|
|
578
|
+
"Tests.lawspec": "exercises/addition/06/Tests.lawspec",
|
|
579
|
+
"Harness.lawspec": "exercises/addition/06/Harness.lawspec",
|
|
580
|
+
"Solution.js": "exercises/addition/05/javascript/Solution.js"
|
|
581
|
+
}
|
|
582
|
+
},
|
|
583
|
+
"previousProjects": {
|
|
584
|
+
"fsharp": {
|
|
585
|
+
"Solution.fs": "module Solution\n\nlet add (x: int) (y: int) : int = x * y\n",
|
|
586
|
+
"Tests.lawspec": "-- ref:DEC-learn-tests-in-lawspec\nunit learn.addition\nadd :: Int32 -> Int32 -> Int32\n\nlaw onePlusTwo is\n definition:\n add 1 2 = 3\n end definition\nend law\n\nlaw twoPlusTwo is\n definition:\n add 2 2 = 4\n end definition\nend law\n\nlaw swapInputs is\n definition:\n for all (x :: Int32 where x >= -10 and x <= 10) (y :: Int32 where y >= -10\n and y <= 10) => add x y = add y x end for all\n end definition\nend law\n\nlaw addOneTwice is\n definition:\n for all (x :: Int32 where x >= -10 and x <= 10) => add 1 (add 1 x) = add 2 x\n end for all\n end definition\nend law\n\nend unit\n",
|
|
587
|
+
"Harness.lawspec": "harness learn.addition.testing for learn.addition is\n strategy numbers :: (n :: Int32 where n >= -2 and n <= 2) is any end strategy\n for law swapInputs\n use numbers for x\n use numbers for y\n end for law\n for law addOneTwice\n use numbers for x\n end for law\nend harness\n"
|
|
588
|
+
},
|
|
589
|
+
"typescript": {
|
|
590
|
+
"Solution.ts": "export function add(x: number, y: number): number\n{\n return x * y;\n}\n",
|
|
591
|
+
"Tests.lawspec": "-- ref:DEC-learn-tests-in-lawspec\nunit learn.addition\nadd :: Int32 -> Int32 -> Int32\n\nlaw onePlusTwo is\n definition:\n add 1 2 = 3\n end definition\nend law\n\nlaw twoPlusTwo is\n definition:\n add 2 2 = 4\n end definition\nend law\n\nlaw swapInputs is\n definition:\n for all (x :: Int32 where x >= -10 and x <= 10) (y :: Int32 where y >= -10\n and y <= 10) => add x y = add y x end for all\n end definition\nend law\n\nlaw addOneTwice is\n definition:\n for all (x :: Int32 where x >= -10 and x <= 10) => add 1 (add 1 x) = add 2 x\n end for all\n end definition\nend law\n\nend unit\n",
|
|
592
|
+
"Harness.lawspec": "harness learn.addition.testing for learn.addition is\n strategy numbers :: (n :: Int32 where n >= -2 and n <= 2) is any end strategy\n for law swapInputs\n use numbers for x\n use numbers for y\n end for law\n for law addOneTwice\n use numbers for x\n end for law\nend harness\n"
|
|
593
|
+
},
|
|
594
|
+
"javascript": {
|
|
595
|
+
"Solution.js": "export function add(x, y)\n{\n return x * y;\n}\n",
|
|
596
|
+
"Tests.lawspec": "-- ref:DEC-learn-tests-in-lawspec\nunit learn.addition\nadd :: Int32 -> Int32 -> Int32\n\nlaw onePlusTwo is\n definition:\n add 1 2 = 3\n end definition\nend law\n\nlaw twoPlusTwo is\n definition:\n add 2 2 = 4\n end definition\nend law\n\nlaw swapInputs is\n definition:\n for all (x :: Int32 where x >= -10 and x <= 10) (y :: Int32 where y >= -10\n and y <= 10) => add x y = add y x end for all\n end definition\nend law\n\nlaw addOneTwice is\n definition:\n for all (x :: Int32 where x >= -10 and x <= 10) => add 1 (add 1 x) = add 2 x\n end for all\n end definition\nend law\n\nend unit\n",
|
|
597
|
+
"Harness.lawspec": "harness learn.addition.testing for learn.addition is\n strategy numbers :: (n :: Int32 where n >= -2 and n <= 2) is any end strategy\n for law swapInputs\n use numbers for x\n use numbers for y\n end for law\n for law addOneTwice\n use numbers for x\n end for law\nend harness\n"
|
|
598
|
+
}
|
|
599
|
+
}
|
|
600
|
+
},
|
|
601
|
+
{
|
|
602
|
+
"id": "zero",
|
|
603
|
+
"title": "An always-zero answer passes both",
|
|
604
|
+
"story": [
|
|
605
|
+
"The calculator now returns 0 for every input. On each side of “swapping the inputs keeps the answer” the result is 0. On each side of “adding one twice agrees with adding two” it is also 0.",
|
|
606
|
+
"Run the sampled properties. Both pass. Generating more inputs cannot rescue these particular claims: neither requires the output to retain anything about its input. The concrete addition examples would still fail in a full run.",
|
|
607
|
+
"We need one more relationship that connects an answer to the input we supplied."
|
|
608
|
+
],
|
|
609
|
+
"focus": "Solution",
|
|
610
|
+
"project": "exercises/addition/07",
|
|
611
|
+
"run": {
|
|
612
|
+
"mode": "sample",
|
|
613
|
+
"expect": "passed",
|
|
614
|
+
"sampled": "passed",
|
|
615
|
+
"seed": 424242
|
|
616
|
+
},
|
|
617
|
+
"action": "Run the sampled properties and trace both equalities with an always-zero function. Identify the connection they are missing.",
|
|
618
|
+
"reason": "Several weak properties can share the same blind spot.",
|
|
619
|
+
"expect": "The supplied code compiles and the selected checks pass. Read which checks actually ran before interpreting this result.",
|
|
620
|
+
"recovery": "Reset this step restores its supplied files and seed. After an edit, use the actual result to judge your version; the story’s prediction describes the supplied files.",
|
|
621
|
+
"editor": "Tests",
|
|
622
|
+
"syntax": "An equality succeeds whenever its two sides agree, even when both results are wrong for the intended operation.",
|
|
623
|
+
"harnessNotes": [
|
|
624
|
+
"numbers draws Int32 integers from -2 through 2, including both endpoints. The variable n describes each candidate value inside the strategy; it is not a separate input to add.",
|
|
625
|
+
"The binding for “swapping the inputs keeps the answer” selects the claim in Laws. use numbers for x and use numbers for y draw the two inputs separately from that recipe. The law permits -10 through 10; this strategy samples a smaller region, so a passing sample cannot establish the whole claim.",
|
|
626
|
+
"The “adding one twice agrees with adding two” binding supplies x from numbers as well. The constants one and two are written in the law; they do not need their own strategies."
|
|
627
|
+
],
|
|
628
|
+
"projects": {
|
|
629
|
+
"fsharp": {
|
|
630
|
+
"Solution.fs": "module Solution\n\nlet add (x: int) (y: int) : int = 0\n",
|
|
631
|
+
"Tests.lawspec": "-- ref:DEC-learn-tests-in-lawspec\nunit learn.addition\nadd :: Int32 -> Int32 -> Int32\n\nlaw \"|one plus two is three| is\n definition:\n add 1 2 = 3\n end definition\nend law\n\nlaw \"|two plus two is four| is\n definition:\n add 2 2 = 4\n end definition\nend law\n\nlaw \"|swapping the inputs keeps the answer| is\n definition:\n for all\n (x :: Int32 where x >= -10 and x <= 10)\n (y :: Int32 where y >= -10 and y <= 10)\n =>\n add x y = add y x\n end for all\n end definition\nend law\n\nlaw \"|adding one twice agrees with adding two| is\n definition:\n for all (x :: Int32 where x >= -10 and x <= 10) =>\n add 1 (add 1 x) = add 2 x\n end for all\n end definition\nend law\n\nend unit\n",
|
|
632
|
+
"Harness.lawspec": "harness learn.addition.testing for learn.addition is\n strategy numbers :: (n :: Int32 where n >= -2 and n <= 2) is any end strategy\n for law \"|swapping the inputs keeps the answer|\n use numbers for x\n use numbers for y\n end for law\n for law \"|adding one twice agrees with adding two|\n use numbers for x\n end for law\nend harness\n"
|
|
633
|
+
},
|
|
634
|
+
"typescript": {
|
|
635
|
+
"Solution.ts": "export function add(x: number, y: number): number\n{\n return 0;\n}\n",
|
|
636
|
+
"Tests.lawspec": "-- ref:DEC-learn-tests-in-lawspec\nunit learn.addition\nadd :: Int32 -> Int32 -> Int32\n\nlaw \"|one plus two is three| is\n definition:\n add 1 2 = 3\n end definition\nend law\n\nlaw \"|two plus two is four| is\n definition:\n add 2 2 = 4\n end definition\nend law\n\nlaw \"|swapping the inputs keeps the answer| is\n definition:\n for all\n (x :: Int32 where x >= -10 and x <= 10)\n (y :: Int32 where y >= -10 and y <= 10)\n =>\n add x y = add y x\n end for all\n end definition\nend law\n\nlaw \"|adding one twice agrees with adding two| is\n definition:\n for all (x :: Int32 where x >= -10 and x <= 10) =>\n add 1 (add 1 x) = add 2 x\n end for all\n end definition\nend law\n\nend unit\n",
|
|
637
|
+
"Harness.lawspec": "harness learn.addition.testing for learn.addition is\n strategy numbers :: (n :: Int32 where n >= -2 and n <= 2) is any end strategy\n for law \"|swapping the inputs keeps the answer|\n use numbers for x\n use numbers for y\n end for law\n for law \"|adding one twice agrees with adding two|\n use numbers for x\n end for law\nend harness\n"
|
|
638
|
+
},
|
|
639
|
+
"javascript": {
|
|
640
|
+
"Solution.js": "export function add(x, y)\n{\n return 0;\n}\n",
|
|
641
|
+
"Tests.lawspec": "-- ref:DEC-learn-tests-in-lawspec\nunit learn.addition\nadd :: Int32 -> Int32 -> Int32\n\nlaw \"|one plus two is three| is\n definition:\n add 1 2 = 3\n end definition\nend law\n\nlaw \"|two plus two is four| is\n definition:\n add 2 2 = 4\n end definition\nend law\n\nlaw \"|swapping the inputs keeps the answer| is\n definition:\n for all\n (x :: Int32 where x >= -10 and x <= 10)\n (y :: Int32 where y >= -10 and y <= 10)\n =>\n add x y = add y x\n end for all\n end definition\nend law\n\nlaw \"|adding one twice agrees with adding two| is\n definition:\n for all (x :: Int32 where x >= -10 and x <= 10) =>\n add 1 (add 1 x) = add 2 x\n end for all\n end definition\nend law\n\nend unit\n",
|
|
642
|
+
"Harness.lawspec": "harness learn.addition.testing for learn.addition is\n strategy numbers :: (n :: Int32 where n >= -2 and n <= 2) is any end strategy\n for law \"|swapping the inputs keeps the answer|\n use numbers for x\n use numbers for y\n end for law\n for law \"|adding one twice agrees with adding two|\n use numbers for x\n end for law\nend harness\n"
|
|
643
|
+
}
|
|
644
|
+
},
|
|
645
|
+
"sources": {
|
|
646
|
+
"fsharp": {
|
|
647
|
+
"Tests.lawspec": "exercises/addition/07/Tests.lawspec",
|
|
648
|
+
"Harness.lawspec": "exercises/addition/07/Harness.lawspec",
|
|
649
|
+
"Solution.fs": "exercises/addition/07/fsharp/Solution.fs"
|
|
650
|
+
},
|
|
651
|
+
"typescript": {
|
|
652
|
+
"Tests.lawspec": "exercises/addition/07/Tests.lawspec",
|
|
653
|
+
"Harness.lawspec": "exercises/addition/07/Harness.lawspec",
|
|
654
|
+
"Solution.ts": "exercises/addition/07/typescript/Solution.ts"
|
|
655
|
+
},
|
|
656
|
+
"javascript": {
|
|
657
|
+
"Tests.lawspec": "exercises/addition/07/Tests.lawspec",
|
|
658
|
+
"Harness.lawspec": "exercises/addition/07/Harness.lawspec",
|
|
659
|
+
"Solution.js": "exercises/addition/07/javascript/Solution.js"
|
|
660
|
+
}
|
|
661
|
+
},
|
|
662
|
+
"previousProjects": {
|
|
663
|
+
"fsharp": {
|
|
664
|
+
"Solution.fs": "module Solution\n\nlet add (x: int) (y: int) : int = 0\n",
|
|
665
|
+
"Tests.lawspec": "-- ref:DEC-learn-tests-in-lawspec\nunit learn.addition\nadd :: Int32 -> Int32 -> Int32\n\nlaw onePlusTwo is\n definition:\n add 1 2 = 3\n end definition\nend law\n\nlaw twoPlusTwo is\n definition:\n add 2 2 = 4\n end definition\nend law\n\nlaw swapInputs is\n definition:\n for all (x :: Int32 where x >= -10 and x <= 10) (y :: Int32 where y >= -10\n and y <= 10) => add x y = add y x end for all\n end definition\nend law\n\nlaw addOneTwice is\n definition:\n for all (x :: Int32 where x >= -10 and x <= 10) => add 1 (add 1 x) = add 2 x\n end for all\n end definition\nend law\n\nend unit\n",
|
|
666
|
+
"Harness.lawspec": "harness learn.addition.testing for learn.addition is\n strategy numbers :: (n :: Int32 where n >= -2 and n <= 2) is any end strategy\n for law swapInputs\n use numbers for x\n use numbers for y\n end for law\n for law addOneTwice\n use numbers for x\n end for law\nend harness\n"
|
|
667
|
+
},
|
|
668
|
+
"typescript": {
|
|
669
|
+
"Solution.ts": "export function add(x: number, y: number): number\n{\n return 0;\n}\n",
|
|
670
|
+
"Tests.lawspec": "-- ref:DEC-learn-tests-in-lawspec\nunit learn.addition\nadd :: Int32 -> Int32 -> Int32\n\nlaw onePlusTwo is\n definition:\n add 1 2 = 3\n end definition\nend law\n\nlaw twoPlusTwo is\n definition:\n add 2 2 = 4\n end definition\nend law\n\nlaw swapInputs is\n definition:\n for all (x :: Int32 where x >= -10 and x <= 10) (y :: Int32 where y >= -10\n and y <= 10) => add x y = add y x end for all\n end definition\nend law\n\nlaw addOneTwice is\n definition:\n for all (x :: Int32 where x >= -10 and x <= 10) => add 1 (add 1 x) = add 2 x\n end for all\n end definition\nend law\n\nend unit\n",
|
|
671
|
+
"Harness.lawspec": "harness learn.addition.testing for learn.addition is\n strategy numbers :: (n :: Int32 where n >= -2 and n <= 2) is any end strategy\n for law swapInputs\n use numbers for x\n use numbers for y\n end for law\n for law addOneTwice\n use numbers for x\n end for law\nend harness\n"
|
|
672
|
+
},
|
|
673
|
+
"javascript": {
|
|
674
|
+
"Solution.js": "export function add(x, y)\n{\n return 0;\n}\n",
|
|
675
|
+
"Tests.lawspec": "-- ref:DEC-learn-tests-in-lawspec\nunit learn.addition\nadd :: Int32 -> Int32 -> Int32\n\nlaw onePlusTwo is\n definition:\n add 1 2 = 3\n end definition\nend law\n\nlaw twoPlusTwo is\n definition:\n add 2 2 = 4\n end definition\nend law\n\nlaw swapInputs is\n definition:\n for all (x :: Int32 where x >= -10 and x <= 10) (y :: Int32 where y >= -10\n and y <= 10) => add x y = add y x end for all\n end definition\nend law\n\nlaw addOneTwice is\n definition:\n for all (x :: Int32 where x >= -10 and x <= 10) => add 1 (add 1 x) = add 2 x\n end for all\n end definition\nend law\n\nend unit\n",
|
|
676
|
+
"Harness.lawspec": "harness learn.addition.testing for learn.addition is\n strategy numbers :: (n :: Int32 where n >= -2 and n <= 2) is any end strategy\n for law swapInputs\n use numbers for x\n use numbers for y\n end for law\n for law addOneTwice\n use numbers for x\n end for law\nend harness\n"
|
|
677
|
+
}
|
|
678
|
+
}
|
|
679
|
+
},
|
|
680
|
+
{
|
|
681
|
+
"id": "repair",
|
|
682
|
+
"title": "Make adding zero preserve the input",
|
|
683
|
+
"story": [
|
|
684
|
+
"Adding zero should leave the other input unchanged. “adding zero keeps the input” now states that connection. Solution still always returns 0.",
|
|
685
|
+
"Use Run checks with All checks first. A nonzero input contradicts “adding zero keeps the input”; the named examples also reject the constant answer. Then implement addition in Solution and rerun without weakening any checks.",
|
|
686
|
+
"After the repair, you will have examples and three relationships that reject the shortcuts we tried. These bounded browser checks are evidence for those runs, not a proof of addition for every integer. As your own challenge, add a named example involving a negative input and explain which shortcut it rejects."
|
|
687
|
+
],
|
|
688
|
+
"focus": "Tests",
|
|
689
|
+
"project": "exercises/addition/08",
|
|
690
|
+
"run": {
|
|
691
|
+
"mode": "all",
|
|
692
|
+
"expect": "failed",
|
|
693
|
+
"sampled": "failed",
|
|
694
|
+
"seed": 424242
|
|
695
|
+
},
|
|
696
|
+
"action": "Observe the failure, implement addition, then rerun the unchanged suite. Add your own negative-input example.",
|
|
697
|
+
"reason": "Which shortcut can still pass? Keep asking that question when you choose properties.",
|
|
698
|
+
"expect": "The supplied code compiles, then the selected checks fail. A compiler error is a different problem; inspect diagnostics if execution did not start.",
|
|
699
|
+
"recovery": "Reset this step restores its supplied files and seed. After an edit, use the actual result to judge your version; the story’s prediction describes the supplied files.",
|
|
700
|
+
"challenge": true,
|
|
701
|
+
"syntax": "“adding zero keeps the input” compares add 0 x with x itself. Unlike the earlier relationships, one side preserves an input directly. Load solution supplies a complete repair on request.",
|
|
702
|
+
"editor": "Solution",
|
|
703
|
+
"harnessNotes": [
|
|
704
|
+
"numbers draws Int32 integers from -2 through 2, including both endpoints. The variable n describes each candidate value inside the strategy; it is not a separate input to add.",
|
|
705
|
+
"The binding for “swapping the inputs keeps the answer” selects the claim in Laws. use numbers for x and use numbers for y draw the two inputs separately from that recipe. The law permits -10 through 10; this strategy samples a smaller region, so a passing sample cannot establish the whole claim.",
|
|
706
|
+
"The “adding one twice agrees with adding two” binding supplies x from numbers as well. The constants one and two are written in the law; they do not need their own strategies.",
|
|
707
|
+
"The “adding zero keeps the input” binding also supplies x. Its zero is a constant in Laws. All three bindings choose data; their corresponding laws decide whether each result passes."
|
|
708
|
+
],
|
|
709
|
+
"projects": {
|
|
710
|
+
"fsharp": {
|
|
711
|
+
"Solution.fs": "module Solution\n\nlet add (x: int) (y: int) : int = 0\n",
|
|
712
|
+
"Tests.lawspec": "-- ref:DEC-learn-tests-in-lawspec\nunit learn.addition\nadd :: Int32 -> Int32 -> Int32\n\nlaw \"|one plus two is three| is\n definition:\n add 1 2 = 3\n end definition\nend law\n\nlaw \"|two plus two is four| is\n definition:\n add 2 2 = 4\n end definition\nend law\n\nlaw \"|swapping the inputs keeps the answer| is\n definition:\n for all\n (x :: Int32 where x >= -10 and x <= 10)\n (y :: Int32 where y >= -10 and y <= 10)\n =>\n add x y = add y x\n end for all\n end definition\nend law\n\nlaw \"|adding one twice agrees with adding two| is\n definition:\n for all (x :: Int32 where x >= -10 and x <= 10) =>\n add 1 (add 1 x) = add 2 x\n end for all\n end definition\nend law\n\nlaw \"|adding zero keeps the input| is\n definition:\n for all (x :: Int32 where x >= -10 and x <= 10) =>\n add 0 x = x\n end for all\n end definition\nend law\n\nend unit\n",
|
|
713
|
+
"Harness.lawspec": "harness learn.addition.testing for learn.addition is\n strategy numbers :: (n :: Int32 where n >= -2 and n <= 2) is any end strategy\n for law \"|swapping the inputs keeps the answer|\n use numbers for x\n use numbers for y\n end for law\n for law \"|adding one twice agrees with adding two|\n use numbers for x\n end for law\n for law \"|adding zero keeps the input|\n use numbers for x\n end for law\nend harness\n"
|
|
714
|
+
},
|
|
715
|
+
"typescript": {
|
|
716
|
+
"Solution.ts": "export function add(x: number, y: number): number\n{\n return 0;\n}\n",
|
|
717
|
+
"Tests.lawspec": "-- ref:DEC-learn-tests-in-lawspec\nunit learn.addition\nadd :: Int32 -> Int32 -> Int32\n\nlaw \"|one plus two is three| is\n definition:\n add 1 2 = 3\n end definition\nend law\n\nlaw \"|two plus two is four| is\n definition:\n add 2 2 = 4\n end definition\nend law\n\nlaw \"|swapping the inputs keeps the answer| is\n definition:\n for all\n (x :: Int32 where x >= -10 and x <= 10)\n (y :: Int32 where y >= -10 and y <= 10)\n =>\n add x y = add y x\n end for all\n end definition\nend law\n\nlaw \"|adding one twice agrees with adding two| is\n definition:\n for all (x :: Int32 where x >= -10 and x <= 10) =>\n add 1 (add 1 x) = add 2 x\n end for all\n end definition\nend law\n\nlaw \"|adding zero keeps the input| is\n definition:\n for all (x :: Int32 where x >= -10 and x <= 10) =>\n add 0 x = x\n end for all\n end definition\nend law\n\nend unit\n",
|
|
718
|
+
"Harness.lawspec": "harness learn.addition.testing for learn.addition is\n strategy numbers :: (n :: Int32 where n >= -2 and n <= 2) is any end strategy\n for law \"|swapping the inputs keeps the answer|\n use numbers for x\n use numbers for y\n end for law\n for law \"|adding one twice agrees with adding two|\n use numbers for x\n end for law\n for law \"|adding zero keeps the input|\n use numbers for x\n end for law\nend harness\n"
|
|
719
|
+
},
|
|
720
|
+
"javascript": {
|
|
721
|
+
"Solution.js": "export function add(x, y)\n{\n return 0;\n}\n",
|
|
722
|
+
"Tests.lawspec": "-- ref:DEC-learn-tests-in-lawspec\nunit learn.addition\nadd :: Int32 -> Int32 -> Int32\n\nlaw \"|one plus two is three| is\n definition:\n add 1 2 = 3\n end definition\nend law\n\nlaw \"|two plus two is four| is\n definition:\n add 2 2 = 4\n end definition\nend law\n\nlaw \"|swapping the inputs keeps the answer| is\n definition:\n for all\n (x :: Int32 where x >= -10 and x <= 10)\n (y :: Int32 where y >= -10 and y <= 10)\n =>\n add x y = add y x\n end for all\n end definition\nend law\n\nlaw \"|adding one twice agrees with adding two| is\n definition:\n for all (x :: Int32 where x >= -10 and x <= 10) =>\n add 1 (add 1 x) = add 2 x\n end for all\n end definition\nend law\n\nlaw \"|adding zero keeps the input| is\n definition:\n for all (x :: Int32 where x >= -10 and x <= 10) =>\n add 0 x = x\n end for all\n end definition\nend law\n\nend unit\n",
|
|
723
|
+
"Harness.lawspec": "harness learn.addition.testing for learn.addition is\n strategy numbers :: (n :: Int32 where n >= -2 and n <= 2) is any end strategy\n for law \"|swapping the inputs keeps the answer|\n use numbers for x\n use numbers for y\n end for law\n for law \"|adding one twice agrees with adding two|\n use numbers for x\n end for law\n for law \"|adding zero keeps the input|\n use numbers for x\n end for law\nend harness\n"
|
|
724
|
+
}
|
|
725
|
+
},
|
|
726
|
+
"sources": {
|
|
727
|
+
"fsharp": {
|
|
728
|
+
"Tests.lawspec": "exercises/addition/08/Tests.lawspec",
|
|
729
|
+
"Harness.lawspec": "exercises/addition/08/Harness.lawspec",
|
|
730
|
+
"Solution.fs": "exercises/addition/07/fsharp/Solution.fs"
|
|
731
|
+
},
|
|
732
|
+
"typescript": {
|
|
733
|
+
"Tests.lawspec": "exercises/addition/08/Tests.lawspec",
|
|
734
|
+
"Harness.lawspec": "exercises/addition/08/Harness.lawspec",
|
|
735
|
+
"Solution.ts": "exercises/addition/07/typescript/Solution.ts"
|
|
736
|
+
},
|
|
737
|
+
"javascript": {
|
|
738
|
+
"Tests.lawspec": "exercises/addition/08/Tests.lawspec",
|
|
739
|
+
"Harness.lawspec": "exercises/addition/08/Harness.lawspec",
|
|
740
|
+
"Solution.js": "exercises/addition/07/javascript/Solution.js"
|
|
741
|
+
}
|
|
742
|
+
},
|
|
743
|
+
"previousProjects": {
|
|
744
|
+
"fsharp": {
|
|
745
|
+
"Solution.fs": "module Solution\n\nlet add (x: int) (y: int) : int = 0\n",
|
|
746
|
+
"Tests.lawspec": "-- ref:DEC-learn-tests-in-lawspec\nunit learn.addition\nadd :: Int32 -> Int32 -> Int32\n\nlaw onePlusTwo is\n definition:\n add 1 2 = 3\n end definition\nend law\n\nlaw twoPlusTwo is\n definition:\n add 2 2 = 4\n end definition\nend law\n\nlaw swapInputs is\n definition:\n for all (x :: Int32 where x >= -10 and x <= 10) (y :: Int32 where y >= -10\n and y <= 10) => add x y = add y x end for all\n end definition\nend law\n\nlaw addOneTwice is\n definition:\n for all (x :: Int32 where x >= -10 and x <= 10) => add 1 (add 1 x) = add 2 x\n end for all\n end definition\nend law\n\nlaw zeroLeavesInput is\n definition:\n for all (x :: Int32 where x >= -10 and x <= 10) => add 0 x = x end for all\n end definition\nend law\n\nend unit\n",
|
|
747
|
+
"Harness.lawspec": "harness learn.addition.testing for learn.addition is\n strategy numbers :: (n :: Int32 where n >= -2 and n <= 2) is any end strategy\n for law swapInputs\n use numbers for x\n use numbers for y\n end for law\n for law addOneTwice\n use numbers for x\n end for law\n for law zeroLeavesInput\n use numbers for x\n end for law\nend harness\n"
|
|
748
|
+
},
|
|
749
|
+
"typescript": {
|
|
750
|
+
"Solution.ts": "export function add(x: number, y: number): number\n{\n return 0;\n}\n",
|
|
751
|
+
"Tests.lawspec": "-- ref:DEC-learn-tests-in-lawspec\nunit learn.addition\nadd :: Int32 -> Int32 -> Int32\n\nlaw onePlusTwo is\n definition:\n add 1 2 = 3\n end definition\nend law\n\nlaw twoPlusTwo is\n definition:\n add 2 2 = 4\n end definition\nend law\n\nlaw swapInputs is\n definition:\n for all (x :: Int32 where x >= -10 and x <= 10) (y :: Int32 where y >= -10\n and y <= 10) => add x y = add y x end for all\n end definition\nend law\n\nlaw addOneTwice is\n definition:\n for all (x :: Int32 where x >= -10 and x <= 10) => add 1 (add 1 x) = add 2 x\n end for all\n end definition\nend law\n\nlaw zeroLeavesInput is\n definition:\n for all (x :: Int32 where x >= -10 and x <= 10) => add 0 x = x end for all\n end definition\nend law\n\nend unit\n",
|
|
752
|
+
"Harness.lawspec": "harness learn.addition.testing for learn.addition is\n strategy numbers :: (n :: Int32 where n >= -2 and n <= 2) is any end strategy\n for law swapInputs\n use numbers for x\n use numbers for y\n end for law\n for law addOneTwice\n use numbers for x\n end for law\n for law zeroLeavesInput\n use numbers for x\n end for law\nend harness\n"
|
|
753
|
+
},
|
|
754
|
+
"javascript": {
|
|
755
|
+
"Solution.js": "export function add(x, y)\n{\n return 0;\n}\n",
|
|
756
|
+
"Tests.lawspec": "-- ref:DEC-learn-tests-in-lawspec\nunit learn.addition\nadd :: Int32 -> Int32 -> Int32\n\nlaw onePlusTwo is\n definition:\n add 1 2 = 3\n end definition\nend law\n\nlaw twoPlusTwo is\n definition:\n add 2 2 = 4\n end definition\nend law\n\nlaw swapInputs is\n definition:\n for all (x :: Int32 where x >= -10 and x <= 10) (y :: Int32 where y >= -10\n and y <= 10) => add x y = add y x end for all\n end definition\nend law\n\nlaw addOneTwice is\n definition:\n for all (x :: Int32 where x >= -10 and x <= 10) => add 1 (add 1 x) = add 2 x\n end for all\n end definition\nend law\n\nlaw zeroLeavesInput is\n definition:\n for all (x :: Int32 where x >= -10 and x <= 10) => add 0 x = x end for all\n end definition\nend law\n\nend unit\n",
|
|
757
|
+
"Harness.lawspec": "harness learn.addition.testing for learn.addition is\n strategy numbers :: (n :: Int32 where n >= -2 and n <= 2) is any end strategy\n for law swapInputs\n use numbers for x\n use numbers for y\n end for law\n for law addOneTwice\n use numbers for x\n end for law\n for law zeroLeavesInput\n use numbers for x\n end for law\nend harness\n"
|
|
758
|
+
}
|
|
759
|
+
}
|
|
760
|
+
}
|
|
761
|
+
],
|
|
762
|
+
"solutionProject": "exercises/addition/solution",
|
|
763
|
+
"coverage": {
|
|
764
|
+
"browserExecution": [
|
|
765
|
+
"fsharp",
|
|
766
|
+
"typescript",
|
|
767
|
+
"javascript"
|
|
768
|
+
],
|
|
769
|
+
"definitionChecking": true,
|
|
770
|
+
"nativeExecution": "deferred",
|
|
771
|
+
"apiCollectionCredit": "deferred: this story is not a complete public API collection"
|
|
772
|
+
},
|
|
773
|
+
"implementationSyntax": {
|
|
774
|
+
"fsharp": "In F#, let add (x: int) (y: int) : int = declares two integer inputs and an integer result. Calls use spaces, as in add x y. if … then … else chooses a result.",
|
|
775
|
+
"typescript": "In TypeScript, add(x: number, y: number): number names typed inputs and a result type. Calls use add(x, y); return supplies the result.",
|
|
776
|
+
"javascript": "In JavaScript, add(x, y) names two inputs. Calls use add(x, y); return supplies the result. Source type annotations are absent."
|
|
777
|
+
},
|
|
778
|
+
"naming": "Use English phrase names for readable claims and descriptive LawSpec helpers. Keep short code names such as add, sort, xs and numbers when they make calls and recipes easier to follow. A phrase starts with \"| and ends with |, without a closing quote. A law label identifies the claim; renaming it does not change what the definition checks. The compiler generates target-appropriate names.",
|
|
779
|
+
"projects": {
|
|
780
|
+
"fsharp": {
|
|
781
|
+
"Solution.fs": "module Solution\n\nlet add (x: int) (y: int) : int = if x = 1 && y = 2 then 3 else 0\n",
|
|
782
|
+
"Tests.lawspec": "-- ref:DEC-learn-tests-in-lawspec\nunit learn.addition\nadd :: Int32 -> Int32 -> Int32\n\nlaw \"|one plus two is three| is\n definition:\n add 1 2 = 3\n end definition\nend law\n\nend unit\n",
|
|
783
|
+
"Harness.lawspec": "harness learn.addition.testing for learn.addition is\n -- This step checks concrete inputs; no generator is selected.\nend harness\n"
|
|
784
|
+
},
|
|
785
|
+
"typescript": {
|
|
786
|
+
"Solution.ts": "export function add(x: number, y: number): number\n{\n return x === 1 && y === 2 ? 3 : 0;\n}\n",
|
|
787
|
+
"Tests.lawspec": "-- ref:DEC-learn-tests-in-lawspec\nunit learn.addition\nadd :: Int32 -> Int32 -> Int32\n\nlaw \"|one plus two is three| is\n definition:\n add 1 2 = 3\n end definition\nend law\n\nend unit\n",
|
|
788
|
+
"Harness.lawspec": "harness learn.addition.testing for learn.addition is\n -- This step checks concrete inputs; no generator is selected.\nend harness\n"
|
|
789
|
+
},
|
|
790
|
+
"javascript": {
|
|
791
|
+
"Solution.js": "export function add(x, y)\n{\n return x === 1 && y === 2 ? 3 : 0;\n}\n",
|
|
792
|
+
"Tests.lawspec": "-- ref:DEC-learn-tests-in-lawspec\nunit learn.addition\nadd :: Int32 -> Int32 -> Int32\n\nlaw \"|one plus two is three| is\n definition:\n add 1 2 = 3\n end definition\nend law\n\nend unit\n",
|
|
793
|
+
"Harness.lawspec": "harness learn.addition.testing for learn.addition is\n -- This step checks concrete inputs; no generator is selected.\nend harness\n"
|
|
794
|
+
}
|
|
795
|
+
},
|
|
796
|
+
"solutions": {
|
|
797
|
+
"fsharp": {
|
|
798
|
+
"Solution.fs": "module Solution\n\nlet add (x: int) (y: int) : int = x + y\n",
|
|
799
|
+
"Tests.lawspec": "-- ref:DEC-learn-tests-in-lawspec\nunit learn.addition\nadd :: Int32 -> Int32 -> Int32\n\nlaw \"|one plus two is three| is\n definition:\n add 1 2 = 3\n end definition\nend law\n\nlaw \"|two plus two is four| is\n definition:\n add 2 2 = 4\n end definition\nend law\n\nlaw \"|swapping the inputs keeps the answer| is\n definition:\n for all\n (x :: Int32 where x >= -10 and x <= 10)\n (y :: Int32 where y >= -10 and y <= 10)\n =>\n add x y = add y x\n end for all\n end definition\nend law\n\nlaw \"|adding one twice agrees with adding two| is\n definition:\n for all (x :: Int32 where x >= -10 and x <= 10) =>\n add 1 (add 1 x) = add 2 x\n end for all\n end definition\nend law\n\nlaw \"|adding zero keeps the input| is\n definition:\n for all (x :: Int32 where x >= -10 and x <= 10) =>\n add 0 x = x\n end for all\n end definition\nend law\n\nend unit\n",
|
|
800
|
+
"Harness.lawspec": "harness learn.addition.testing for learn.addition is\n strategy numbers :: (n :: Int32 where n >= -2 and n <= 2) is any end strategy\n for law \"|swapping the inputs keeps the answer|\n use numbers for x\n use numbers for y\n end for law\n for law \"|adding one twice agrees with adding two|\n use numbers for x\n end for law\n for law \"|adding zero keeps the input|\n use numbers for x\n end for law\nend harness\n"
|
|
801
|
+
},
|
|
802
|
+
"typescript": {
|
|
803
|
+
"Solution.ts": "export function add(x: number, y: number): number\n{\n return x + y;\n}\n",
|
|
804
|
+
"Tests.lawspec": "-- ref:DEC-learn-tests-in-lawspec\nunit learn.addition\nadd :: Int32 -> Int32 -> Int32\n\nlaw \"|one plus two is three| is\n definition:\n add 1 2 = 3\n end definition\nend law\n\nlaw \"|two plus two is four| is\n definition:\n add 2 2 = 4\n end definition\nend law\n\nlaw \"|swapping the inputs keeps the answer| is\n definition:\n for all\n (x :: Int32 where x >= -10 and x <= 10)\n (y :: Int32 where y >= -10 and y <= 10)\n =>\n add x y = add y x\n end for all\n end definition\nend law\n\nlaw \"|adding one twice agrees with adding two| is\n definition:\n for all (x :: Int32 where x >= -10 and x <= 10) =>\n add 1 (add 1 x) = add 2 x\n end for all\n end definition\nend law\n\nlaw \"|adding zero keeps the input| is\n definition:\n for all (x :: Int32 where x >= -10 and x <= 10) =>\n add 0 x = x\n end for all\n end definition\nend law\n\nend unit\n",
|
|
805
|
+
"Harness.lawspec": "harness learn.addition.testing for learn.addition is\n strategy numbers :: (n :: Int32 where n >= -2 and n <= 2) is any end strategy\n for law \"|swapping the inputs keeps the answer|\n use numbers for x\n use numbers for y\n end for law\n for law \"|adding one twice agrees with adding two|\n use numbers for x\n end for law\n for law \"|adding zero keeps the input|\n use numbers for x\n end for law\nend harness\n"
|
|
806
|
+
},
|
|
807
|
+
"javascript": {
|
|
808
|
+
"Solution.js": "export function add(x, y)\n{\n return x + y;\n}\n",
|
|
809
|
+
"Tests.lawspec": "-- ref:DEC-learn-tests-in-lawspec\nunit learn.addition\nadd :: Int32 -> Int32 -> Int32\n\nlaw \"|one plus two is three| is\n definition:\n add 1 2 = 3\n end definition\nend law\n\nlaw \"|two plus two is four| is\n definition:\n add 2 2 = 4\n end definition\nend law\n\nlaw \"|swapping the inputs keeps the answer| is\n definition:\n for all\n (x :: Int32 where x >= -10 and x <= 10)\n (y :: Int32 where y >= -10 and y <= 10)\n =>\n add x y = add y x\n end for all\n end definition\nend law\n\nlaw \"|adding one twice agrees with adding two| is\n definition:\n for all (x :: Int32 where x >= -10 and x <= 10) =>\n add 1 (add 1 x) = add 2 x\n end for all\n end definition\nend law\n\nlaw \"|adding zero keeps the input| is\n definition:\n for all (x :: Int32 where x >= -10 and x <= 10) =>\n add 0 x = x\n end for all\n end definition\nend law\n\nend unit\n",
|
|
810
|
+
"Harness.lawspec": "harness learn.addition.testing for learn.addition is\n strategy numbers :: (n :: Int32 where n >= -2 and n <= 2) is any end strategy\n for law \"|swapping the inputs keeps the answer|\n use numbers for x\n use numbers for y\n end for law\n for law \"|adding one twice agrees with adding two|\n use numbers for x\n end for law\n for law \"|adding zero keeps the input|\n use numbers for x\n end for law\nend harness\n"
|
|
811
|
+
}
|
|
812
|
+
},
|
|
813
|
+
"solutionSources": {
|
|
814
|
+
"fsharp": {
|
|
815
|
+
"Tests.lawspec": "exercises/addition/solution/Tests.lawspec",
|
|
816
|
+
"Harness.lawspec": "exercises/addition/solution/Harness.lawspec",
|
|
817
|
+
"Solution.fs": "exercises/addition/solution/fsharp/Solution.fs"
|
|
818
|
+
},
|
|
819
|
+
"typescript": {
|
|
820
|
+
"Tests.lawspec": "exercises/addition/solution/Tests.lawspec",
|
|
821
|
+
"Harness.lawspec": "exercises/addition/solution/Harness.lawspec",
|
|
822
|
+
"Solution.ts": "exercises/addition/solution/typescript/Solution.ts"
|
|
823
|
+
},
|
|
824
|
+
"javascript": {
|
|
825
|
+
"Tests.lawspec": "exercises/addition/solution/Tests.lawspec",
|
|
826
|
+
"Harness.lawspec": "exercises/addition/solution/Harness.lawspec",
|
|
827
|
+
"Solution.js": "exercises/addition/solution/javascript/Solution.js"
|
|
828
|
+
}
|
|
829
|
+
}
|
|
830
|
+
},
|
|
831
|
+
{
|
|
832
|
+
"id": "wlaschin-sort",
|
|
833
|
+
"title": "Can an empty answer pass a sorting test?",
|
|
834
|
+
"section": "Wlaschin’s examples",
|
|
835
|
+
"vision": "Learn to specify a sort that orders values while keeping every occurrence.",
|
|
836
|
+
"slogan": "Order it. Keep it.",
|
|
837
|
+
"symbol": "[3, 1, 1] → []: ordered, but lost",
|
|
838
|
+
"explanation": "Laws and generation strategies are authored in LawSpec. Only the implementation changes language.",
|
|
839
|
+
"news": "Sorting must preserve occurrences as well as order values.",
|
|
840
|
+
"contributions": "A sort, an adjacent-order check and an occurrence-count preservation check. The same suite rejects empty output, lost duplicates, substituted values and unchanged unsorted input, and accepts a correct sort.",
|
|
841
|
+
"star": {
|
|
842
|
+
"salient": "Sorting must preserve occurrences as well as order values.",
|
|
843
|
+
"slogan": "Order it. Keep it.",
|
|
844
|
+
"symbol": "[3, 1, 1] → []: ordered, but lost",
|
|
845
|
+
"surprise": "An empty list passes an adjacent-order check because there is no out-of-order pair.",
|
|
846
|
+
"story": "A sorter discards everything and passes ordering. Preservation exposes it, duplicate loss and substitution; keeping the input exposes the remaining need for ordering."
|
|
847
|
+
},
|
|
848
|
+
"attribution": [
|
|
849
|
+
{
|
|
850
|
+
"title": "Scott Wlaschin — Choosing properties in practice, part 1",
|
|
851
|
+
"url": "https://fsharpforfunandprofit.com/posts/property-based-testing-3/",
|
|
852
|
+
"use": "Adapted ordered-output and preservation examples, expressed with an adjacent-order helper and LawSpec’s sameItems operation. Preservation does not call a reference sort."
|
|
853
|
+
}
|
|
854
|
+
],
|
|
855
|
+
"hints": [
|
|
856
|
+
"Count occurrences in the concrete failing example.",
|
|
857
|
+
"If preservation passes, look for an adjacent pair in the wrong order.",
|
|
858
|
+
"Keep both requirements and sort the original values. Load solution reveals the complete implementation."
|
|
859
|
+
],
|
|
860
|
+
"stages": [
|
|
861
|
+
{
|
|
862
|
+
"id": "empty",
|
|
863
|
+
"title": "An empty answer looks ordered",
|
|
864
|
+
"story": [
|
|
865
|
+
"We want a function that puts integers in ascending order. If the input contains the same value twice, both occurrences must remain. For example, sorting three values must still return those three values. By the end, you will have two complementary requirements that distinguish sorting from losing or replacing values.",
|
|
866
|
+
"An occurrence means one appearance of a value. If a list contains 1 twice, it has two occurrences of 1. Sorting changes positions; it should not change those counts.",
|
|
867
|
+
"Our current property checks only ordered: every adjacent pair in the result is in ascending order. Solution returns an empty list for every input. Before running, decide whether an empty list contains an out-of-order pair.",
|
|
868
|
+
"Use Run checks with All checks. The pass is real: an empty list has no bad pair. It still fails our purpose because it loses every input value.",
|
|
869
|
+
"Open Harness to see how xs is chosen. number draws integers; bind draws a, b and c; one of builds lists of zero through three items. use lists for xs supplies “the result is in ascending order”. These are small teaching inputs, not all possible lists."
|
|
870
|
+
],
|
|
871
|
+
"focus": "Solution",
|
|
872
|
+
"project": "exercises/sorting/01",
|
|
873
|
+
"run": {
|
|
874
|
+
"mode": "all",
|
|
875
|
+
"expect": "passed",
|
|
876
|
+
"seed": 424242
|
|
877
|
+
},
|
|
878
|
+
"action": "Run the current suite. Explain why ordered accepts [] and what useful behavior the property omits.",
|
|
879
|
+
"reason": "The unexpected pass tells us which part of sorting we have not specified.",
|
|
880
|
+
"expect": "The supplied code compiles and the selected checks pass. Read which checks actually ran before interpreting this result.",
|
|
881
|
+
"recovery": "Reset this step restores its supplied files and seed. After an edit, use the actual result to judge your version; the story’s prediction describes the supplied files.",
|
|
882
|
+
"syntax": "The helper \"|is in ascending order| returns true or false. Nil is an empty list; Cons separates a first item from the remaining list. The helper checks an adjacent pair and calls itself on the remaining list until it reaches the end. Its descriptive phrase becomes an ordinary function name in generated code.",
|
|
883
|
+
"editor": "Tests",
|
|
884
|
+
"harnessNotes": [
|
|
885
|
+
"number draws integers from -20 through 20. The short-list strategy draws a, b and c from number using nested bind expressions: each bind makes its drawn value available inside the following expression.",
|
|
886
|
+
"one of chooses between [], [a], [a, b] and [a, b, c]. These are lists of zero through three items; repeated values are possible. This recipe does not generate arbitrary-length lists. Shrinking can try smaller choices and smaller elements, keeping only candidates that still fail.",
|
|
887
|
+
"The binding for “the result is in ascending order” selects the claim in Laws; use lists for xs supplies its list input xs. The implementation returns a result, and the law checks it. The generator does not provide the expected answer."
|
|
888
|
+
],
|
|
889
|
+
"symbol": "[3, 1, 1] → []: ordered, but lost",
|
|
890
|
+
"projects": {
|
|
891
|
+
"fsharp": {
|
|
892
|
+
"Solution.fs": "module Solution\n\nlet sort (xs: int list) : int list = []\n",
|
|
893
|
+
"Tests.lawspec": "-- ref:DEC-learn-tests-in-lawspec\nunit learn.sorting\nsort :: List Int32 -> List Int32\n\nfunction \"|is in ascending order| (xs :: List Int32) -> Bool is\n first matching case of xs :\n when Nil then true\n when Cons h t then\n (first matching case of t :\n when Nil then true\n when Cons next rest then h <= next and \"|is in ascending order| t\n end case)\n end case\nend function\n\nlaw \"|an empty input stays empty| is\n definition:\n sort [] = []\n end definition\nend law\n\nlaw \"|the result is in ascending order| is\n definition:\n for all (xs :: List Int32) =>\n \"|is in ascending order| (sort xs) = true\n end for all\n end definition\nend law\n\nend unit\n",
|
|
894
|
+
"Harness.lawspec": "harness learn.sorting.testing for learn.sorting is\n strategy number :: (n :: Int32 where n >= -20 and n <= 20) is any end strategy\n\n -- Draw up to three items constructively; shrinking follows these choices.\n strategy lists :: List Int32 is\n bind a :: Int32 from number in\n bind b :: Int32 from number in\n bind c :: Int32 from number in\n one of [], [a], [a, b], [a, b, c]\n end bind end bind end bind\n end strategy\n\n for law \"|the result is in ascending order|\n use lists for xs\n end for law\nend harness\n"
|
|
895
|
+
},
|
|
896
|
+
"typescript": {
|
|
897
|
+
"Solution.ts": "export function sort(xs: number[]): number[]\n{\n return [];\n}\n",
|
|
898
|
+
"Tests.lawspec": "-- ref:DEC-learn-tests-in-lawspec\nunit learn.sorting\nsort :: List Int32 -> List Int32\n\nfunction \"|is in ascending order| (xs :: List Int32) -> Bool is\n first matching case of xs :\n when Nil then true\n when Cons h t then\n (first matching case of t :\n when Nil then true\n when Cons next rest then h <= next and \"|is in ascending order| t\n end case)\n end case\nend function\n\nlaw \"|an empty input stays empty| is\n definition:\n sort [] = []\n end definition\nend law\n\nlaw \"|the result is in ascending order| is\n definition:\n for all (xs :: List Int32) =>\n \"|is in ascending order| (sort xs) = true\n end for all\n end definition\nend law\n\nend unit\n",
|
|
899
|
+
"Harness.lawspec": "harness learn.sorting.testing for learn.sorting is\n strategy number :: (n :: Int32 where n >= -20 and n <= 20) is any end strategy\n\n -- Draw up to three items constructively; shrinking follows these choices.\n strategy lists :: List Int32 is\n bind a :: Int32 from number in\n bind b :: Int32 from number in\n bind c :: Int32 from number in\n one of [], [a], [a, b], [a, b, c]\n end bind end bind end bind\n end strategy\n\n for law \"|the result is in ascending order|\n use lists for xs\n end for law\nend harness\n"
|
|
900
|
+
},
|
|
901
|
+
"javascript": {
|
|
902
|
+
"Solution.js": "export function sort(xs)\n{\n return [];\n}\n",
|
|
903
|
+
"Tests.lawspec": "-- ref:DEC-learn-tests-in-lawspec\nunit learn.sorting\nsort :: List Int32 -> List Int32\n\nfunction \"|is in ascending order| (xs :: List Int32) -> Bool is\n first matching case of xs :\n when Nil then true\n when Cons h t then\n (first matching case of t :\n when Nil then true\n when Cons next rest then h <= next and \"|is in ascending order| t\n end case)\n end case\nend function\n\nlaw \"|an empty input stays empty| is\n definition:\n sort [] = []\n end definition\nend law\n\nlaw \"|the result is in ascending order| is\n definition:\n for all (xs :: List Int32) =>\n \"|is in ascending order| (sort xs) = true\n end for all\n end definition\nend law\n\nend unit\n",
|
|
904
|
+
"Harness.lawspec": "harness learn.sorting.testing for learn.sorting is\n strategy number :: (n :: Int32 where n >= -20 and n <= 20) is any end strategy\n\n -- Draw up to three items constructively; shrinking follows these choices.\n strategy lists :: List Int32 is\n bind a :: Int32 from number in\n bind b :: Int32 from number in\n bind c :: Int32 from number in\n one of [], [a], [a, b], [a, b, c]\n end bind end bind end bind\n end strategy\n\n for law \"|the result is in ascending order|\n use lists for xs\n end for law\nend harness\n"
|
|
905
|
+
}
|
|
906
|
+
},
|
|
907
|
+
"sources": {
|
|
908
|
+
"fsharp": {
|
|
909
|
+
"Tests.lawspec": "exercises/sorting/01/Tests.lawspec",
|
|
910
|
+
"Harness.lawspec": "exercises/sorting/01/Harness.lawspec",
|
|
911
|
+
"Solution.fs": "exercises/sorting/01/fsharp/Solution.fs"
|
|
912
|
+
},
|
|
913
|
+
"typescript": {
|
|
914
|
+
"Tests.lawspec": "exercises/sorting/01/Tests.lawspec",
|
|
915
|
+
"Harness.lawspec": "exercises/sorting/01/Harness.lawspec",
|
|
916
|
+
"Solution.ts": "exercises/sorting/01/typescript/Solution.ts"
|
|
917
|
+
},
|
|
918
|
+
"javascript": {
|
|
919
|
+
"Tests.lawspec": "exercises/sorting/01/Tests.lawspec",
|
|
920
|
+
"Harness.lawspec": "exercises/sorting/01/Harness.lawspec",
|
|
921
|
+
"Solution.js": "exercises/sorting/01/javascript/Solution.js"
|
|
922
|
+
}
|
|
923
|
+
},
|
|
924
|
+
"previousProjects": {
|
|
925
|
+
"fsharp": {
|
|
926
|
+
"Solution.fs": "module Solution\n\nlet sort (xs: int list) : int list = []\n",
|
|
927
|
+
"Tests.lawspec": "-- ref:DEC-learn-tests-in-lawspec\nunit learn.sorting\nsort :: List Int32 -> List Int32\n\nfunction ordered (xs :: List Int32) -> Bool is\n first matching case of xs :\n when Nil then true\n when Cons h t then\n (first matching case of t :\n when Nil then true\n when Cons next rest then h <= next and ordered t\n end case)\n end case\nend function\n\nlaw emptyInput is\n definition:\n sort [] = []\n end definition\nend law\n\nlaw sortingRule is\n definition:\n for all (xs :: List Int32) => ordered (sort xs) = true end for all\n end definition\nend law\n\nend unit\n",
|
|
928
|
+
"Harness.lawspec": "harness learn.sorting.testing for learn.sorting is\n strategy number :: (n :: Int32 where n >= -20 and n <= 20) is any end strategy\n\n -- Draw up to three items constructively; shrinking follows these choices.\n strategy lists :: List Int32 is\n bind a :: Int32 from number in\n bind b :: Int32 from number in\n bind c :: Int32 from number in\n one of [], [a], [a, b], [a, b, c]\n end bind end bind end bind\n end strategy\n\n for law sortingRule\n use lists for xs\n end for law\nend harness\n"
|
|
929
|
+
},
|
|
930
|
+
"typescript": {
|
|
931
|
+
"Solution.ts": "export function sort(xs: number[]): number[]\n{\n return [];\n}\n",
|
|
932
|
+
"Tests.lawspec": "-- ref:DEC-learn-tests-in-lawspec\nunit learn.sorting\nsort :: List Int32 -> List Int32\n\nfunction ordered (xs :: List Int32) -> Bool is\n first matching case of xs :\n when Nil then true\n when Cons h t then\n (first matching case of t :\n when Nil then true\n when Cons next rest then h <= next and ordered t\n end case)\n end case\nend function\n\nlaw emptyInput is\n definition:\n sort [] = []\n end definition\nend law\n\nlaw sortingRule is\n definition:\n for all (xs :: List Int32) => ordered (sort xs) = true end for all\n end definition\nend law\n\nend unit\n",
|
|
933
|
+
"Harness.lawspec": "harness learn.sorting.testing for learn.sorting is\n strategy number :: (n :: Int32 where n >= -20 and n <= 20) is any end strategy\n\n -- Draw up to three items constructively; shrinking follows these choices.\n strategy lists :: List Int32 is\n bind a :: Int32 from number in\n bind b :: Int32 from number in\n bind c :: Int32 from number in\n one of [], [a], [a, b], [a, b, c]\n end bind end bind end bind\n end strategy\n\n for law sortingRule\n use lists for xs\n end for law\nend harness\n"
|
|
934
|
+
},
|
|
935
|
+
"javascript": {
|
|
936
|
+
"Solution.js": "export function sort(xs)\n{\n return [];\n}\n",
|
|
937
|
+
"Tests.lawspec": "-- ref:DEC-learn-tests-in-lawspec\nunit learn.sorting\nsort :: List Int32 -> List Int32\n\nfunction ordered (xs :: List Int32) -> Bool is\n first matching case of xs :\n when Nil then true\n when Cons h t then\n (first matching case of t :\n when Nil then true\n when Cons next rest then h <= next and ordered t\n end case)\n end case\nend function\n\nlaw emptyInput is\n definition:\n sort [] = []\n end definition\nend law\n\nlaw sortingRule is\n definition:\n for all (xs :: List Int32) => ordered (sort xs) = true end for all\n end definition\nend law\n\nend unit\n",
|
|
938
|
+
"Harness.lawspec": "harness learn.sorting.testing for learn.sorting is\n strategy number :: (n :: Int32 where n >= -20 and n <= 20) is any end strategy\n\n -- Draw up to three items constructively; shrinking follows these choices.\n strategy lists :: List Int32 is\n bind a :: Int32 from number in\n bind b :: Int32 from number in\n bind c :: Int32 from number in\n one of [], [a], [a, b], [a, b, c]\n end bind end bind end bind\n end strategy\n\n for law sortingRule\n use lists for xs\n end for law\nend harness\n"
|
|
939
|
+
}
|
|
940
|
+
}
|
|
941
|
+
},
|
|
942
|
+
{
|
|
943
|
+
"id": "preserve",
|
|
944
|
+
"title": "Require the same values, with the same counts",
|
|
945
|
+
"story": [
|
|
946
|
+
"Laws adds sameItems to “sorting orders values and keeps every occurrence”. It requires each value to occur just as many times in the result as in the input. Ordering remains required too.",
|
|
947
|
+
"Solution still returns []. The concrete “sorting keeps repeated values” law now expects the sorted form of [3, 1, 1]. Use Run checks with All checks: preservation rejects the lost values.",
|
|
948
|
+
"This is stronger than asking whether values merely appear somewhere in the result. Two occurrences of 1 must remain two occurrences.",
|
|
949
|
+
"Read the whole new claim name: “sorting orders values and keeps every occurrence”. and joins the two requirements. The harness refers to this same name so its generated lists reach the strengthened claim."
|
|
950
|
+
],
|
|
951
|
+
"focus": "Tests",
|
|
952
|
+
"project": "exercises/sorting/02",
|
|
953
|
+
"run": {
|
|
954
|
+
"mode": "all",
|
|
955
|
+
"expect": "failed",
|
|
956
|
+
"failedTests": [
|
|
957
|
+
"learn.sorting::|sorting keeps repeated values| boundary 1"
|
|
958
|
+
],
|
|
959
|
+
"sampled": "failed",
|
|
960
|
+
"seed": 424242
|
|
961
|
+
},
|
|
962
|
+
"action": "Use Run checks with All checks. Read “sorting keeps repeated values” and explain which input occurrences are absent from the actual result.",
|
|
963
|
+
"reason": "A useful sorting contract must account for every occurrence.",
|
|
964
|
+
"expect": "The supplied code compiles, then the selected checks fail. A compiler error is a different problem; inspect diagnostics if execution did not start.",
|
|
965
|
+
"recovery": "Reset this step restores its supplied files and seed. After an edit, use the actual result to judge your version; the story’s prediction describes the supplied files.",
|
|
966
|
+
"editor": "Solution",
|
|
967
|
+
"syntax": "sameItems compares occurrence counts while ignoring order. and requires both ordering and preservation to hold.",
|
|
968
|
+
"harnessNotes": [
|
|
969
|
+
"number draws integers from -20 through 20. The short-list strategy draws a, b and c from number using nested bind expressions: each bind makes its drawn value available inside the following expression.",
|
|
970
|
+
"one of chooses between [], [a], [a, b] and [a, b, c]. These are lists of zero through three items; repeated values are possible. This recipe does not generate arbitrary-length lists. Shrinking can try smaller choices and smaller elements, keeping only candidates that still fail.",
|
|
971
|
+
"The binding for “sorting orders values and keeps every occurrence” selects the claim in Laws; use lists for xs supplies its list input xs. The implementation returns a result, and the law checks it. The generator does not provide the expected answer."
|
|
972
|
+
],
|
|
973
|
+
"projects": {
|
|
974
|
+
"fsharp": {
|
|
975
|
+
"Solution.fs": "module Solution\n\nlet sort (xs: int list) : int list = []\n",
|
|
976
|
+
"Tests.lawspec": "-- ref:DEC-learn-tests-in-lawspec\nunit learn.sorting\nsort :: List Int32 -> List Int32\n\nfunction \"|is in ascending order| (xs :: List Int32) -> Bool is\n first matching case of xs :\n when Nil then true\n when Cons h t then\n (first matching case of t :\n when Nil then true\n when Cons next rest then h <= next and \"|is in ascending order| t\n end case)\n end case\nend function\n\nlaw \"|an empty input stays empty| is\n definition:\n sort [] = []\n end definition\nend law\n\nlaw \"|sorting keeps repeated values| is\n definition:\n sort [3, 1, 1] = [1, 1, 3]\n end definition\nend law\n\nlaw \"|sorting orders values and keeps every occurrence| is\n definition:\n for all (xs :: List Int32) =>\n \"|is in ascending order| (sort xs) = true and sameItems (sort xs) xs\n end for all\n end definition\nend law\n\nend unit\n",
|
|
977
|
+
"Harness.lawspec": "harness learn.sorting.testing for learn.sorting is\n strategy number :: (n :: Int32 where n >= -20 and n <= 20) is any end strategy\n\n -- Draw up to three items constructively; shrinking follows these choices.\n strategy lists :: List Int32 is\n bind a :: Int32 from number in\n bind b :: Int32 from number in\n bind c :: Int32 from number in\n one of [], [a], [a, b], [a, b, c]\n end bind end bind end bind\n end strategy\n\n for law \"|sorting orders values and keeps every occurrence|\n use lists for xs\n end for law\nend harness\n"
|
|
978
|
+
},
|
|
979
|
+
"typescript": {
|
|
980
|
+
"Solution.ts": "export function sort(xs: number[]): number[]\n{\n return [];\n}\n",
|
|
981
|
+
"Tests.lawspec": "-- ref:DEC-learn-tests-in-lawspec\nunit learn.sorting\nsort :: List Int32 -> List Int32\n\nfunction \"|is in ascending order| (xs :: List Int32) -> Bool is\n first matching case of xs :\n when Nil then true\n when Cons h t then\n (first matching case of t :\n when Nil then true\n when Cons next rest then h <= next and \"|is in ascending order| t\n end case)\n end case\nend function\n\nlaw \"|an empty input stays empty| is\n definition:\n sort [] = []\n end definition\nend law\n\nlaw \"|sorting keeps repeated values| is\n definition:\n sort [3, 1, 1] = [1, 1, 3]\n end definition\nend law\n\nlaw \"|sorting orders values and keeps every occurrence| is\n definition:\n for all (xs :: List Int32) =>\n \"|is in ascending order| (sort xs) = true and sameItems (sort xs) xs\n end for all\n end definition\nend law\n\nend unit\n",
|
|
982
|
+
"Harness.lawspec": "harness learn.sorting.testing for learn.sorting is\n strategy number :: (n :: Int32 where n >= -20 and n <= 20) is any end strategy\n\n -- Draw up to three items constructively; shrinking follows these choices.\n strategy lists :: List Int32 is\n bind a :: Int32 from number in\n bind b :: Int32 from number in\n bind c :: Int32 from number in\n one of [], [a], [a, b], [a, b, c]\n end bind end bind end bind\n end strategy\n\n for law \"|sorting orders values and keeps every occurrence|\n use lists for xs\n end for law\nend harness\n"
|
|
983
|
+
},
|
|
984
|
+
"javascript": {
|
|
985
|
+
"Solution.js": "export function sort(xs)\n{\n return [];\n}\n",
|
|
986
|
+
"Tests.lawspec": "-- ref:DEC-learn-tests-in-lawspec\nunit learn.sorting\nsort :: List Int32 -> List Int32\n\nfunction \"|is in ascending order| (xs :: List Int32) -> Bool is\n first matching case of xs :\n when Nil then true\n when Cons h t then\n (first matching case of t :\n when Nil then true\n when Cons next rest then h <= next and \"|is in ascending order| t\n end case)\n end case\nend function\n\nlaw \"|an empty input stays empty| is\n definition:\n sort [] = []\n end definition\nend law\n\nlaw \"|sorting keeps repeated values| is\n definition:\n sort [3, 1, 1] = [1, 1, 3]\n end definition\nend law\n\nlaw \"|sorting orders values and keeps every occurrence| is\n definition:\n for all (xs :: List Int32) =>\n \"|is in ascending order| (sort xs) = true and sameItems (sort xs) xs\n end for all\n end definition\nend law\n\nend unit\n",
|
|
987
|
+
"Harness.lawspec": "harness learn.sorting.testing for learn.sorting is\n strategy number :: (n :: Int32 where n >= -20 and n <= 20) is any end strategy\n\n -- Draw up to three items constructively; shrinking follows these choices.\n strategy lists :: List Int32 is\n bind a :: Int32 from number in\n bind b :: Int32 from number in\n bind c :: Int32 from number in\n one of [], [a], [a, b], [a, b, c]\n end bind end bind end bind\n end strategy\n\n for law \"|sorting orders values and keeps every occurrence|\n use lists for xs\n end for law\nend harness\n"
|
|
988
|
+
}
|
|
989
|
+
},
|
|
990
|
+
"sources": {
|
|
991
|
+
"fsharp": {
|
|
992
|
+
"Tests.lawspec": "exercises/sorting/02/Tests.lawspec",
|
|
993
|
+
"Harness.lawspec": "exercises/sorting/02/Harness.lawspec",
|
|
994
|
+
"Solution.fs": "exercises/sorting/01/fsharp/Solution.fs"
|
|
995
|
+
},
|
|
996
|
+
"typescript": {
|
|
997
|
+
"Tests.lawspec": "exercises/sorting/02/Tests.lawspec",
|
|
998
|
+
"Harness.lawspec": "exercises/sorting/02/Harness.lawspec",
|
|
999
|
+
"Solution.ts": "exercises/sorting/01/typescript/Solution.ts"
|
|
1000
|
+
},
|
|
1001
|
+
"javascript": {
|
|
1002
|
+
"Tests.lawspec": "exercises/sorting/02/Tests.lawspec",
|
|
1003
|
+
"Harness.lawspec": "exercises/sorting/02/Harness.lawspec",
|
|
1004
|
+
"Solution.js": "exercises/sorting/01/javascript/Solution.js"
|
|
1005
|
+
}
|
|
1006
|
+
},
|
|
1007
|
+
"previousProjects": {
|
|
1008
|
+
"fsharp": {
|
|
1009
|
+
"Solution.fs": "module Solution\n\nlet sort (xs: int list) : int list = []\n",
|
|
1010
|
+
"Tests.lawspec": "-- ref:DEC-learn-tests-in-lawspec\nunit learn.sorting\nsort :: List Int32 -> List Int32\n\nfunction ordered (xs :: List Int32) -> Bool is\n first matching case of xs :\n when Nil then true\n when Cons h t then\n (first matching case of t :\n when Nil then true\n when Cons next rest then h <= next and ordered t\n end case)\n end case\nend function\n\nlaw emptyInput is\n definition:\n sort [] = []\n end definition\nend law\n\nlaw duplicateRequests is\n definition:\n sort [3, 1, 1] = [1, 1, 3]\n end definition\nend law\n\nlaw sortingRule is\n definition:\n for all (xs :: List Int32) => ordered (sort xs) = true and sameItems (sort\n xs) xs end for all\n end definition\nend law\n\nend unit\n",
|
|
1011
|
+
"Harness.lawspec": "harness learn.sorting.testing for learn.sorting is\n strategy number :: (n :: Int32 where n >= -20 and n <= 20) is any end strategy\n\n -- Draw up to three items constructively; shrinking follows these choices.\n strategy lists :: List Int32 is\n bind a :: Int32 from number in\n bind b :: Int32 from number in\n bind c :: Int32 from number in\n one of [], [a], [a, b], [a, b, c]\n end bind end bind end bind\n end strategy\n\n for law sortingRule\n use lists for xs\n end for law\nend harness\n"
|
|
1012
|
+
},
|
|
1013
|
+
"typescript": {
|
|
1014
|
+
"Solution.ts": "export function sort(xs: number[]): number[]\n{\n return [];\n}\n",
|
|
1015
|
+
"Tests.lawspec": "-- ref:DEC-learn-tests-in-lawspec\nunit learn.sorting\nsort :: List Int32 -> List Int32\n\nfunction ordered (xs :: List Int32) -> Bool is\n first matching case of xs :\n when Nil then true\n when Cons h t then\n (first matching case of t :\n when Nil then true\n when Cons next rest then h <= next and ordered t\n end case)\n end case\nend function\n\nlaw emptyInput is\n definition:\n sort [] = []\n end definition\nend law\n\nlaw duplicateRequests is\n definition:\n sort [3, 1, 1] = [1, 1, 3]\n end definition\nend law\n\nlaw sortingRule is\n definition:\n for all (xs :: List Int32) => ordered (sort xs) = true and sameItems (sort\n xs) xs end for all\n end definition\nend law\n\nend unit\n",
|
|
1016
|
+
"Harness.lawspec": "harness learn.sorting.testing for learn.sorting is\n strategy number :: (n :: Int32 where n >= -20 and n <= 20) is any end strategy\n\n -- Draw up to three items constructively; shrinking follows these choices.\n strategy lists :: List Int32 is\n bind a :: Int32 from number in\n bind b :: Int32 from number in\n bind c :: Int32 from number in\n one of [], [a], [a, b], [a, b, c]\n end bind end bind end bind\n end strategy\n\n for law sortingRule\n use lists for xs\n end for law\nend harness\n"
|
|
1017
|
+
},
|
|
1018
|
+
"javascript": {
|
|
1019
|
+
"Solution.js": "export function sort(xs)\n{\n return [];\n}\n",
|
|
1020
|
+
"Tests.lawspec": "-- ref:DEC-learn-tests-in-lawspec\nunit learn.sorting\nsort :: List Int32 -> List Int32\n\nfunction ordered (xs :: List Int32) -> Bool is\n first matching case of xs :\n when Nil then true\n when Cons h t then\n (first matching case of t :\n when Nil then true\n when Cons next rest then h <= next and ordered t\n end case)\n end case\nend function\n\nlaw emptyInput is\n definition:\n sort [] = []\n end definition\nend law\n\nlaw duplicateRequests is\n definition:\n sort [3, 1, 1] = [1, 1, 3]\n end definition\nend law\n\nlaw sortingRule is\n definition:\n for all (xs :: List Int32) => ordered (sort xs) = true and sameItems (sort\n xs) xs end for all\n end definition\nend law\n\nend unit\n",
|
|
1021
|
+
"Harness.lawspec": "harness learn.sorting.testing for learn.sorting is\n strategy number :: (n :: Int32 where n >= -20 and n <= 20) is any end strategy\n\n -- Draw up to three items constructively; shrinking follows these choices.\n strategy lists :: List Int32 is\n bind a :: Int32 from number in\n bind b :: Int32 from number in\n bind c :: Int32 from number in\n one of [], [a], [a, b], [a, b, c]\n end bind end bind end bind\n end strategy\n\n for law sortingRule\n use lists for xs\n end for law\nend harness\n"
|
|
1022
|
+
}
|
|
1023
|
+
}
|
|
1024
|
+
},
|
|
1025
|
+
{
|
|
1026
|
+
"id": "duplicates",
|
|
1027
|
+
"title": "Removing duplicates also loses occurrences",
|
|
1028
|
+
"story": [
|
|
1029
|
+
"This version removes duplicate values and then sorts. The result of the concrete check contains one 1 instead of two.",
|
|
1030
|
+
"The result is ordered, but its occurrence counts are wrong. Run the unchanged suite. We do not need a special property for this new shortcut: sameItems already rejects it."
|
|
1031
|
+
],
|
|
1032
|
+
"focus": "Solution",
|
|
1033
|
+
"project": "exercises/sorting/03",
|
|
1034
|
+
"run": {
|
|
1035
|
+
"mode": "all",
|
|
1036
|
+
"expect": "failed",
|
|
1037
|
+
"failedTests": [
|
|
1038
|
+
"learn.sorting::|sorting keeps repeated values| boundary 1"
|
|
1039
|
+
],
|
|
1040
|
+
"sampled": "failed",
|
|
1041
|
+
"seed": 424242
|
|
1042
|
+
},
|
|
1043
|
+
"action": "Run the suite and count the 1s on both sides of “sorting keeps repeated values”.",
|
|
1044
|
+
"reason": "Distinct values and all original occurrences answer different questions.",
|
|
1045
|
+
"expect": "The supplied code compiles, then the selected checks fail. A compiler error is a different problem; inspect diagnostics if execution did not start.",
|
|
1046
|
+
"recovery": "Reset this step restores its supplied files and seed. After an edit, use the actual result to judge your version; the story’s prediction describes the supplied files.",
|
|
1047
|
+
"editor": "Tests",
|
|
1048
|
+
"syntax": "The sameItems requirement checks repeated occurrences. A membership-only check would not distinguish one 1 from two 1s.",
|
|
1049
|
+
"harnessNotes": [
|
|
1050
|
+
"number draws integers from -20 through 20. The short-list strategy draws a, b and c from number using nested bind expressions: each bind makes its drawn value available inside the following expression.",
|
|
1051
|
+
"one of chooses between [], [a], [a, b] and [a, b, c]. These are lists of zero through three items; repeated values are possible. This recipe does not generate arbitrary-length lists. Shrinking can try smaller choices and smaller elements, keeping only candidates that still fail.",
|
|
1052
|
+
"The binding for “sorting orders values and keeps every occurrence” selects the claim in Laws; use lists for xs supplies its list input xs. The implementation returns a result, and the law checks it. The generator does not provide the expected answer."
|
|
1053
|
+
],
|
|
1054
|
+
"projects": {
|
|
1055
|
+
"fsharp": {
|
|
1056
|
+
"Solution.fs": "module Solution\n\nlet sort (xs: int list) : int list = List.distinct xs |> List.sort\n",
|
|
1057
|
+
"Tests.lawspec": "-- ref:DEC-learn-tests-in-lawspec\nunit learn.sorting\nsort :: List Int32 -> List Int32\n\nfunction \"|is in ascending order| (xs :: List Int32) -> Bool is\n first matching case of xs :\n when Nil then true\n when Cons h t then\n (first matching case of t :\n when Nil then true\n when Cons next rest then h <= next and \"|is in ascending order| t\n end case)\n end case\nend function\n\nlaw \"|an empty input stays empty| is\n definition:\n sort [] = []\n end definition\nend law\n\nlaw \"|sorting keeps repeated values| is\n definition:\n sort [3, 1, 1] = [1, 1, 3]\n end definition\nend law\n\nlaw \"|sorting orders values and keeps every occurrence| is\n definition:\n for all (xs :: List Int32) =>\n \"|is in ascending order| (sort xs) = true and sameItems (sort xs) xs\n end for all\n end definition\nend law\n\nend unit\n",
|
|
1058
|
+
"Harness.lawspec": "harness learn.sorting.testing for learn.sorting is\n strategy number :: (n :: Int32 where n >= -20 and n <= 20) is any end strategy\n\n -- Draw up to three items constructively; shrinking follows these choices.\n strategy lists :: List Int32 is\n bind a :: Int32 from number in\n bind b :: Int32 from number in\n bind c :: Int32 from number in\n one of [], [a], [a, b], [a, b, c]\n end bind end bind end bind\n end strategy\n\n for law \"|sorting orders values and keeps every occurrence|\n use lists for xs\n end for law\nend harness\n"
|
|
1059
|
+
},
|
|
1060
|
+
"typescript": {
|
|
1061
|
+
"Solution.ts": "export function sort(xs: number[]): number[]\n{\n return [...new Set(xs)].sort((a, b) => a - b);\n}\n",
|
|
1062
|
+
"Tests.lawspec": "-- ref:DEC-learn-tests-in-lawspec\nunit learn.sorting\nsort :: List Int32 -> List Int32\n\nfunction \"|is in ascending order| (xs :: List Int32) -> Bool is\n first matching case of xs :\n when Nil then true\n when Cons h t then\n (first matching case of t :\n when Nil then true\n when Cons next rest then h <= next and \"|is in ascending order| t\n end case)\n end case\nend function\n\nlaw \"|an empty input stays empty| is\n definition:\n sort [] = []\n end definition\nend law\n\nlaw \"|sorting keeps repeated values| is\n definition:\n sort [3, 1, 1] = [1, 1, 3]\n end definition\nend law\n\nlaw \"|sorting orders values and keeps every occurrence| is\n definition:\n for all (xs :: List Int32) =>\n \"|is in ascending order| (sort xs) = true and sameItems (sort xs) xs\n end for all\n end definition\nend law\n\nend unit\n",
|
|
1063
|
+
"Harness.lawspec": "harness learn.sorting.testing for learn.sorting is\n strategy number :: (n :: Int32 where n >= -20 and n <= 20) is any end strategy\n\n -- Draw up to three items constructively; shrinking follows these choices.\n strategy lists :: List Int32 is\n bind a :: Int32 from number in\n bind b :: Int32 from number in\n bind c :: Int32 from number in\n one of [], [a], [a, b], [a, b, c]\n end bind end bind end bind\n end strategy\n\n for law \"|sorting orders values and keeps every occurrence|\n use lists for xs\n end for law\nend harness\n"
|
|
1064
|
+
},
|
|
1065
|
+
"javascript": {
|
|
1066
|
+
"Solution.js": "export function sort(xs)\n{\n return [...new Set(xs)].sort((a, b) => a - b);\n}\n",
|
|
1067
|
+
"Tests.lawspec": "-- ref:DEC-learn-tests-in-lawspec\nunit learn.sorting\nsort :: List Int32 -> List Int32\n\nfunction \"|is in ascending order| (xs :: List Int32) -> Bool is\n first matching case of xs :\n when Nil then true\n when Cons h t then\n (first matching case of t :\n when Nil then true\n when Cons next rest then h <= next and \"|is in ascending order| t\n end case)\n end case\nend function\n\nlaw \"|an empty input stays empty| is\n definition:\n sort [] = []\n end definition\nend law\n\nlaw \"|sorting keeps repeated values| is\n definition:\n sort [3, 1, 1] = [1, 1, 3]\n end definition\nend law\n\nlaw \"|sorting orders values and keeps every occurrence| is\n definition:\n for all (xs :: List Int32) =>\n \"|is in ascending order| (sort xs) = true and sameItems (sort xs) xs\n end for all\n end definition\nend law\n\nend unit\n",
|
|
1068
|
+
"Harness.lawspec": "harness learn.sorting.testing for learn.sorting is\n strategy number :: (n :: Int32 where n >= -20 and n <= 20) is any end strategy\n\n -- Draw up to three items constructively; shrinking follows these choices.\n strategy lists :: List Int32 is\n bind a :: Int32 from number in\n bind b :: Int32 from number in\n bind c :: Int32 from number in\n one of [], [a], [a, b], [a, b, c]\n end bind end bind end bind\n end strategy\n\n for law \"|sorting orders values and keeps every occurrence|\n use lists for xs\n end for law\nend harness\n"
|
|
1069
|
+
}
|
|
1070
|
+
},
|
|
1071
|
+
"sources": {
|
|
1072
|
+
"fsharp": {
|
|
1073
|
+
"Tests.lawspec": "exercises/sorting/03/Tests.lawspec",
|
|
1074
|
+
"Harness.lawspec": "exercises/sorting/03/Harness.lawspec",
|
|
1075
|
+
"Solution.fs": "exercises/sorting/03/fsharp/Solution.fs"
|
|
1076
|
+
},
|
|
1077
|
+
"typescript": {
|
|
1078
|
+
"Tests.lawspec": "exercises/sorting/03/Tests.lawspec",
|
|
1079
|
+
"Harness.lawspec": "exercises/sorting/03/Harness.lawspec",
|
|
1080
|
+
"Solution.ts": "exercises/sorting/03/typescript/Solution.ts"
|
|
1081
|
+
},
|
|
1082
|
+
"javascript": {
|
|
1083
|
+
"Tests.lawspec": "exercises/sorting/03/Tests.lawspec",
|
|
1084
|
+
"Harness.lawspec": "exercises/sorting/03/Harness.lawspec",
|
|
1085
|
+
"Solution.js": "exercises/sorting/03/javascript/Solution.js"
|
|
1086
|
+
}
|
|
1087
|
+
},
|
|
1088
|
+
"previousProjects": {
|
|
1089
|
+
"fsharp": {
|
|
1090
|
+
"Solution.fs": "module Solution\n\nlet sort (xs: int list) : int list = List.distinct xs |> List.sort\n",
|
|
1091
|
+
"Tests.lawspec": "-- ref:DEC-learn-tests-in-lawspec\nunit learn.sorting\nsort :: List Int32 -> List Int32\n\nfunction ordered (xs :: List Int32) -> Bool is\n first matching case of xs :\n when Nil then true\n when Cons h t then\n (first matching case of t :\n when Nil then true\n when Cons next rest then h <= next and ordered t\n end case)\n end case\nend function\n\nlaw emptyInput is\n definition:\n sort [] = []\n end definition\nend law\n\nlaw duplicateRequests is\n definition:\n sort [3, 1, 1] = [1, 1, 3]\n end definition\nend law\n\nlaw sortingRule is\n definition:\n for all (xs :: List Int32) => ordered (sort xs) = true and sameItems (sort\n xs) xs end for all\n end definition\nend law\n\nend unit\n",
|
|
1092
|
+
"Harness.lawspec": "harness learn.sorting.testing for learn.sorting is\n strategy number :: (n :: Int32 where n >= -20 and n <= 20) is any end strategy\n\n -- Draw up to three items constructively; shrinking follows these choices.\n strategy lists :: List Int32 is\n bind a :: Int32 from number in\n bind b :: Int32 from number in\n bind c :: Int32 from number in\n one of [], [a], [a, b], [a, b, c]\n end bind end bind end bind\n end strategy\n\n for law sortingRule\n use lists for xs\n end for law\nend harness\n"
|
|
1093
|
+
},
|
|
1094
|
+
"typescript": {
|
|
1095
|
+
"Solution.ts": "export function sort(xs: number[]): number[]\n{\n return [...new Set(xs)].sort((a, b) => a - b);\n}\n",
|
|
1096
|
+
"Tests.lawspec": "-- ref:DEC-learn-tests-in-lawspec\nunit learn.sorting\nsort :: List Int32 -> List Int32\n\nfunction ordered (xs :: List Int32) -> Bool is\n first matching case of xs :\n when Nil then true\n when Cons h t then\n (first matching case of t :\n when Nil then true\n when Cons next rest then h <= next and ordered t\n end case)\n end case\nend function\n\nlaw emptyInput is\n definition:\n sort [] = []\n end definition\nend law\n\nlaw duplicateRequests is\n definition:\n sort [3, 1, 1] = [1, 1, 3]\n end definition\nend law\n\nlaw sortingRule is\n definition:\n for all (xs :: List Int32) => ordered (sort xs) = true and sameItems (sort\n xs) xs end for all\n end definition\nend law\n\nend unit\n",
|
|
1097
|
+
"Harness.lawspec": "harness learn.sorting.testing for learn.sorting is\n strategy number :: (n :: Int32 where n >= -20 and n <= 20) is any end strategy\n\n -- Draw up to three items constructively; shrinking follows these choices.\n strategy lists :: List Int32 is\n bind a :: Int32 from number in\n bind b :: Int32 from number in\n bind c :: Int32 from number in\n one of [], [a], [a, b], [a, b, c]\n end bind end bind end bind\n end strategy\n\n for law sortingRule\n use lists for xs\n end for law\nend harness\n"
|
|
1098
|
+
},
|
|
1099
|
+
"javascript": {
|
|
1100
|
+
"Solution.js": "export function sort(xs)\n{\n return [...new Set(xs)].sort((a, b) => a - b);\n}\n",
|
|
1101
|
+
"Tests.lawspec": "-- ref:DEC-learn-tests-in-lawspec\nunit learn.sorting\nsort :: List Int32 -> List Int32\n\nfunction ordered (xs :: List Int32) -> Bool is\n first matching case of xs :\n when Nil then true\n when Cons h t then\n (first matching case of t :\n when Nil then true\n when Cons next rest then h <= next and ordered t\n end case)\n end case\nend function\n\nlaw emptyInput is\n definition:\n sort [] = []\n end definition\nend law\n\nlaw duplicateRequests is\n definition:\n sort [3, 1, 1] = [1, 1, 3]\n end definition\nend law\n\nlaw sortingRule is\n definition:\n for all (xs :: List Int32) => ordered (sort xs) = true and sameItems (sort\n xs) xs end for all\n end definition\nend law\n\nend unit\n",
|
|
1102
|
+
"Harness.lawspec": "harness learn.sorting.testing for learn.sorting is\n strategy number :: (n :: Int32 where n >= -20 and n <= 20) is any end strategy\n\n -- Draw up to three items constructively; shrinking follows these choices.\n strategy lists :: List Int32 is\n bind a :: Int32 from number in\n bind b :: Int32 from number in\n bind c :: Int32 from number in\n one of [], [a], [a, b], [a, b, c]\n end bind end bind end bind\n end strategy\n\n for law sortingRule\n use lists for xs\n end for law\nend harness\n"
|
|
1103
|
+
}
|
|
1104
|
+
}
|
|
1105
|
+
},
|
|
1106
|
+
{
|
|
1107
|
+
"id": "substitute",
|
|
1108
|
+
"title": "Keeping the length can still replace the values",
|
|
1109
|
+
"story": [
|
|
1110
|
+
"This implementation returns one zero for each input item. It keeps the length and its zeros are ordered.",
|
|
1111
|
+
"Run the same suite. Whenever the input contains another value, the occurrence counts disagree. Keeping three positions is not enough if we replace the things in them."
|
|
1112
|
+
],
|
|
1113
|
+
"focus": "Solution",
|
|
1114
|
+
"project": "exercises/sorting/04",
|
|
1115
|
+
"run": {
|
|
1116
|
+
"mode": "all",
|
|
1117
|
+
"expect": "failed",
|
|
1118
|
+
"sampled": "failed",
|
|
1119
|
+
"seed": 424242
|
|
1120
|
+
},
|
|
1121
|
+
"action": "Use Run checks with All checks. Identify a value whose count changed despite the correct output length.",
|
|
1122
|
+
"reason": "Order it. Keep it. Preservation covers replacement as well as removal.",
|
|
1123
|
+
"expect": "The supplied code compiles, then the selected checks fail. A compiler error is a different problem; inspect diagnostics if execution did not start.",
|
|
1124
|
+
"recovery": "Reset this step restores its supplied files and seed. After an edit, use the actual result to judge your version; the story’s prediction describes the supplied files.",
|
|
1125
|
+
"editor": "Tests",
|
|
1126
|
+
"syntax": "sameItems checks which values occur and how often. Equal list lengths alone cannot establish that.",
|
|
1127
|
+
"harnessNotes": [
|
|
1128
|
+
"number draws integers from -20 through 20. The short-list strategy draws a, b and c from number using nested bind expressions: each bind makes its drawn value available inside the following expression.",
|
|
1129
|
+
"one of chooses between [], [a], [a, b] and [a, b, c]. These are lists of zero through three items; repeated values are possible. This recipe does not generate arbitrary-length lists. Shrinking can try smaller choices and smaller elements, keeping only candidates that still fail.",
|
|
1130
|
+
"The binding for “sorting orders values and keeps every occurrence” selects the claim in Laws; use lists for xs supplies its list input xs. The implementation returns a result, and the law checks it. The generator does not provide the expected answer."
|
|
1131
|
+
],
|
|
1132
|
+
"projects": {
|
|
1133
|
+
"fsharp": {
|
|
1134
|
+
"Solution.fs": "module Solution\n\nlet sort (xs: int list) : int list = List.map (fun _ -> 0) xs\n",
|
|
1135
|
+
"Tests.lawspec": "-- ref:DEC-learn-tests-in-lawspec\nunit learn.sorting\nsort :: List Int32 -> List Int32\n\nfunction \"|is in ascending order| (xs :: List Int32) -> Bool is\n first matching case of xs :\n when Nil then true\n when Cons h t then\n (first matching case of t :\n when Nil then true\n when Cons next rest then h <= next and \"|is in ascending order| t\n end case)\n end case\nend function\n\nlaw \"|an empty input stays empty| is\n definition:\n sort [] = []\n end definition\nend law\n\nlaw \"|sorting keeps repeated values| is\n definition:\n sort [3, 1, 1] = [1, 1, 3]\n end definition\nend law\n\nlaw \"|sorting orders values and keeps every occurrence| is\n definition:\n for all (xs :: List Int32) =>\n \"|is in ascending order| (sort xs) = true and sameItems (sort xs) xs\n end for all\n end definition\nend law\n\nend unit\n",
|
|
1136
|
+
"Harness.lawspec": "harness learn.sorting.testing for learn.sorting is\n strategy number :: (n :: Int32 where n >= -20 and n <= 20) is any end strategy\n\n -- Draw up to three items constructively; shrinking follows these choices.\n strategy lists :: List Int32 is\n bind a :: Int32 from number in\n bind b :: Int32 from number in\n bind c :: Int32 from number in\n one of [], [a], [a, b], [a, b, c]\n end bind end bind end bind\n end strategy\n\n for law \"|sorting orders values and keeps every occurrence|\n use lists for xs\n end for law\nend harness\n"
|
|
1137
|
+
},
|
|
1138
|
+
"typescript": {
|
|
1139
|
+
"Solution.ts": "export function sort(xs: number[]): number[]\n{\n return xs.map(() => 0);\n}\n",
|
|
1140
|
+
"Tests.lawspec": "-- ref:DEC-learn-tests-in-lawspec\nunit learn.sorting\nsort :: List Int32 -> List Int32\n\nfunction \"|is in ascending order| (xs :: List Int32) -> Bool is\n first matching case of xs :\n when Nil then true\n when Cons h t then\n (first matching case of t :\n when Nil then true\n when Cons next rest then h <= next and \"|is in ascending order| t\n end case)\n end case\nend function\n\nlaw \"|an empty input stays empty| is\n definition:\n sort [] = []\n end definition\nend law\n\nlaw \"|sorting keeps repeated values| is\n definition:\n sort [3, 1, 1] = [1, 1, 3]\n end definition\nend law\n\nlaw \"|sorting orders values and keeps every occurrence| is\n definition:\n for all (xs :: List Int32) =>\n \"|is in ascending order| (sort xs) = true and sameItems (sort xs) xs\n end for all\n end definition\nend law\n\nend unit\n",
|
|
1141
|
+
"Harness.lawspec": "harness learn.sorting.testing for learn.sorting is\n strategy number :: (n :: Int32 where n >= -20 and n <= 20) is any end strategy\n\n -- Draw up to three items constructively; shrinking follows these choices.\n strategy lists :: List Int32 is\n bind a :: Int32 from number in\n bind b :: Int32 from number in\n bind c :: Int32 from number in\n one of [], [a], [a, b], [a, b, c]\n end bind end bind end bind\n end strategy\n\n for law \"|sorting orders values and keeps every occurrence|\n use lists for xs\n end for law\nend harness\n"
|
|
1142
|
+
},
|
|
1143
|
+
"javascript": {
|
|
1144
|
+
"Solution.js": "export function sort(xs)\n{\n return xs.map(() => 0);\n}\n",
|
|
1145
|
+
"Tests.lawspec": "-- ref:DEC-learn-tests-in-lawspec\nunit learn.sorting\nsort :: List Int32 -> List Int32\n\nfunction \"|is in ascending order| (xs :: List Int32) -> Bool is\n first matching case of xs :\n when Nil then true\n when Cons h t then\n (first matching case of t :\n when Nil then true\n when Cons next rest then h <= next and \"|is in ascending order| t\n end case)\n end case\nend function\n\nlaw \"|an empty input stays empty| is\n definition:\n sort [] = []\n end definition\nend law\n\nlaw \"|sorting keeps repeated values| is\n definition:\n sort [3, 1, 1] = [1, 1, 3]\n end definition\nend law\n\nlaw \"|sorting orders values and keeps every occurrence| is\n definition:\n for all (xs :: List Int32) =>\n \"|is in ascending order| (sort xs) = true and sameItems (sort xs) xs\n end for all\n end definition\nend law\n\nend unit\n",
|
|
1146
|
+
"Harness.lawspec": "harness learn.sorting.testing for learn.sorting is\n strategy number :: (n :: Int32 where n >= -20 and n <= 20) is any end strategy\n\n -- Draw up to three items constructively; shrinking follows these choices.\n strategy lists :: List Int32 is\n bind a :: Int32 from number in\n bind b :: Int32 from number in\n bind c :: Int32 from number in\n one of [], [a], [a, b], [a, b, c]\n end bind end bind end bind\n end strategy\n\n for law \"|sorting orders values and keeps every occurrence|\n use lists for xs\n end for law\nend harness\n"
|
|
1147
|
+
}
|
|
1148
|
+
},
|
|
1149
|
+
"sources": {
|
|
1150
|
+
"fsharp": {
|
|
1151
|
+
"Tests.lawspec": "exercises/sorting/04/Tests.lawspec",
|
|
1152
|
+
"Harness.lawspec": "exercises/sorting/04/Harness.lawspec",
|
|
1153
|
+
"Solution.fs": "exercises/sorting/04/fsharp/Solution.fs"
|
|
1154
|
+
},
|
|
1155
|
+
"typescript": {
|
|
1156
|
+
"Tests.lawspec": "exercises/sorting/04/Tests.lawspec",
|
|
1157
|
+
"Harness.lawspec": "exercises/sorting/04/Harness.lawspec",
|
|
1158
|
+
"Solution.ts": "exercises/sorting/04/typescript/Solution.ts"
|
|
1159
|
+
},
|
|
1160
|
+
"javascript": {
|
|
1161
|
+
"Tests.lawspec": "exercises/sorting/04/Tests.lawspec",
|
|
1162
|
+
"Harness.lawspec": "exercises/sorting/04/Harness.lawspec",
|
|
1163
|
+
"Solution.js": "exercises/sorting/04/javascript/Solution.js"
|
|
1164
|
+
}
|
|
1165
|
+
},
|
|
1166
|
+
"previousProjects": {
|
|
1167
|
+
"fsharp": {
|
|
1168
|
+
"Solution.fs": "module Solution\n\nlet sort (xs: int list) : int list = List.map (fun _ -> 0) xs\n",
|
|
1169
|
+
"Tests.lawspec": "-- ref:DEC-learn-tests-in-lawspec\nunit learn.sorting\nsort :: List Int32 -> List Int32\n\nfunction ordered (xs :: List Int32) -> Bool is\n first matching case of xs :\n when Nil then true\n when Cons h t then\n (first matching case of t :\n when Nil then true\n when Cons next rest then h <= next and ordered t\n end case)\n end case\nend function\n\nlaw emptyInput is\n definition:\n sort [] = []\n end definition\nend law\n\nlaw duplicateRequests is\n definition:\n sort [3, 1, 1] = [1, 1, 3]\n end definition\nend law\n\nlaw sortingRule is\n definition:\n for all (xs :: List Int32) => ordered (sort xs) = true and sameItems (sort\n xs) xs end for all\n end definition\nend law\n\nend unit\n",
|
|
1170
|
+
"Harness.lawspec": "harness learn.sorting.testing for learn.sorting is\n strategy number :: (n :: Int32 where n >= -20 and n <= 20) is any end strategy\n\n -- Draw up to three items constructively; shrinking follows these choices.\n strategy lists :: List Int32 is\n bind a :: Int32 from number in\n bind b :: Int32 from number in\n bind c :: Int32 from number in\n one of [], [a], [a, b], [a, b, c]\n end bind end bind end bind\n end strategy\n\n for law sortingRule\n use lists for xs\n end for law\nend harness\n"
|
|
1171
|
+
},
|
|
1172
|
+
"typescript": {
|
|
1173
|
+
"Solution.ts": "export function sort(xs: number[]): number[]\n{\n return xs.map(() => 0);\n}\n",
|
|
1174
|
+
"Tests.lawspec": "-- ref:DEC-learn-tests-in-lawspec\nunit learn.sorting\nsort :: List Int32 -> List Int32\n\nfunction ordered (xs :: List Int32) -> Bool is\n first matching case of xs :\n when Nil then true\n when Cons h t then\n (first matching case of t :\n when Nil then true\n when Cons next rest then h <= next and ordered t\n end case)\n end case\nend function\n\nlaw emptyInput is\n definition:\n sort [] = []\n end definition\nend law\n\nlaw duplicateRequests is\n definition:\n sort [3, 1, 1] = [1, 1, 3]\n end definition\nend law\n\nlaw sortingRule is\n definition:\n for all (xs :: List Int32) => ordered (sort xs) = true and sameItems (sort\n xs) xs end for all\n end definition\nend law\n\nend unit\n",
|
|
1175
|
+
"Harness.lawspec": "harness learn.sorting.testing for learn.sorting is\n strategy number :: (n :: Int32 where n >= -20 and n <= 20) is any end strategy\n\n -- Draw up to three items constructively; shrinking follows these choices.\n strategy lists :: List Int32 is\n bind a :: Int32 from number in\n bind b :: Int32 from number in\n bind c :: Int32 from number in\n one of [], [a], [a, b], [a, b, c]\n end bind end bind end bind\n end strategy\n\n for law sortingRule\n use lists for xs\n end for law\nend harness\n"
|
|
1176
|
+
},
|
|
1177
|
+
"javascript": {
|
|
1178
|
+
"Solution.js": "export function sort(xs)\n{\n return xs.map(() => 0);\n}\n",
|
|
1179
|
+
"Tests.lawspec": "-- ref:DEC-learn-tests-in-lawspec\nunit learn.sorting\nsort :: List Int32 -> List Int32\n\nfunction ordered (xs :: List Int32) -> Bool is\n first matching case of xs :\n when Nil then true\n when Cons h t then\n (first matching case of t :\n when Nil then true\n when Cons next rest then h <= next and ordered t\n end case)\n end case\nend function\n\nlaw emptyInput is\n definition:\n sort [] = []\n end definition\nend law\n\nlaw duplicateRequests is\n definition:\n sort [3, 1, 1] = [1, 1, 3]\n end definition\nend law\n\nlaw sortingRule is\n definition:\n for all (xs :: List Int32) => ordered (sort xs) = true and sameItems (sort\n xs) xs end for all\n end definition\nend law\n\nend unit\n",
|
|
1180
|
+
"Harness.lawspec": "harness learn.sorting.testing for learn.sorting is\n strategy number :: (n :: Int32 where n >= -20 and n <= 20) is any end strategy\n\n -- Draw up to three items constructively; shrinking follows these choices.\n strategy lists :: List Int32 is\n bind a :: Int32 from number in\n bind b :: Int32 from number in\n bind c :: Int32 from number in\n one of [], [a], [a, b], [a, b, c]\n end bind end bind end bind\n end strategy\n\n for law sortingRule\n use lists for xs\n end for law\nend harness\n"
|
|
1181
|
+
}
|
|
1182
|
+
}
|
|
1183
|
+
},
|
|
1184
|
+
{
|
|
1185
|
+
"id": "repair",
|
|
1186
|
+
"title": "Satisfy both halves of sorting",
|
|
1187
|
+
"story": [
|
|
1188
|
+
"The starter now returns its input unchanged. Every occurrence survives, but an unsorted input remains unsorted.",
|
|
1189
|
+
"Run this version to see the ordering failure. Then implement an ascending sort in Solution and rerun both requirements. Keep the named example and sameItems.",
|
|
1190
|
+
"You will have a sorter checked against both obligations. As your own challenge, add a concrete example with a negative value and a repeated value. Explain why returning the input and removing duplicates each break it."
|
|
1191
|
+
],
|
|
1192
|
+
"focus": "Solution",
|
|
1193
|
+
"project": "exercises/sorting/05",
|
|
1194
|
+
"run": {
|
|
1195
|
+
"mode": "all",
|
|
1196
|
+
"expect": "failed",
|
|
1197
|
+
"sampled": "failed",
|
|
1198
|
+
"seed": 424242
|
|
1199
|
+
},
|
|
1200
|
+
"action": "Observe the ordering failure, implement a correct sort and rerun. Add an example that exercises both requirements.",
|
|
1201
|
+
"reason": "Neither ordering nor preservation is sufficient by itself.",
|
|
1202
|
+
"expect": "The supplied code compiles, then the selected checks fail. A compiler error is a different problem; inspect diagnostics if execution did not start.",
|
|
1203
|
+
"recovery": "Reset this step restores its supplied files and seed. After an edit, use the actual result to judge your version; the story’s prediction describes the supplied files.",
|
|
1204
|
+
"challenge": true,
|
|
1205
|
+
"editor": "Tests",
|
|
1206
|
+
"syntax": "ordering and sameItems are joined by and. A correct result must satisfy both; weakening either one reopens an escape route.",
|
|
1207
|
+
"harnessNotes": [
|
|
1208
|
+
"number draws integers from -20 through 20. The short-list strategy draws a, b and c from number using nested bind expressions: each bind makes its drawn value available inside the following expression.",
|
|
1209
|
+
"one of chooses between [], [a], [a, b] and [a, b, c]. These are lists of zero through three items; repeated values are possible. This recipe does not generate arbitrary-length lists. Shrinking can try smaller choices and smaller elements, keeping only candidates that still fail.",
|
|
1210
|
+
"The binding for “sorting orders values and keeps every occurrence” selects the claim in Laws; use lists for xs supplies its list input xs. The implementation returns a result, and the law checks it. The generator does not provide the expected answer."
|
|
1211
|
+
],
|
|
1212
|
+
"projects": {
|
|
1213
|
+
"fsharp": {
|
|
1214
|
+
"Solution.fs": "module Solution\n\nlet sort (xs: int list) : int list = xs\n",
|
|
1215
|
+
"Tests.lawspec": "-- ref:DEC-learn-tests-in-lawspec\nunit learn.sorting\nsort :: List Int32 -> List Int32\n\nfunction \"|is in ascending order| (xs :: List Int32) -> Bool is\n first matching case of xs :\n when Nil then true\n when Cons h t then\n (first matching case of t :\n when Nil then true\n when Cons next rest then h <= next and \"|is in ascending order| t\n end case)\n end case\nend function\n\nlaw \"|an empty input stays empty| is\n definition:\n sort [] = []\n end definition\nend law\n\nlaw \"|sorting keeps repeated values| is\n definition:\n sort [3, 1, 1] = [1, 1, 3]\n end definition\nend law\n\nlaw \"|sorting orders values and keeps every occurrence| is\n definition:\n for all (xs :: List Int32) =>\n \"|is in ascending order| (sort xs) = true and sameItems (sort xs) xs\n end for all\n end definition\nend law\n\nend unit\n",
|
|
1216
|
+
"Harness.lawspec": "harness learn.sorting.testing for learn.sorting is\n strategy number :: (n :: Int32 where n >= -20 and n <= 20) is any end strategy\n\n -- Draw up to three items constructively; shrinking follows these choices.\n strategy lists :: List Int32 is\n bind a :: Int32 from number in\n bind b :: Int32 from number in\n bind c :: Int32 from number in\n one of [], [a], [a, b], [a, b, c]\n end bind end bind end bind\n end strategy\n\n for law \"|sorting orders values and keeps every occurrence|\n use lists for xs\n end for law\nend harness\n"
|
|
1217
|
+
},
|
|
1218
|
+
"typescript": {
|
|
1219
|
+
"Solution.ts": "export function sort(xs: number[]): number[]\n{\n return xs;\n}\n",
|
|
1220
|
+
"Tests.lawspec": "-- ref:DEC-learn-tests-in-lawspec\nunit learn.sorting\nsort :: List Int32 -> List Int32\n\nfunction \"|is in ascending order| (xs :: List Int32) -> Bool is\n first matching case of xs :\n when Nil then true\n when Cons h t then\n (first matching case of t :\n when Nil then true\n when Cons next rest then h <= next and \"|is in ascending order| t\n end case)\n end case\nend function\n\nlaw \"|an empty input stays empty| is\n definition:\n sort [] = []\n end definition\nend law\n\nlaw \"|sorting keeps repeated values| is\n definition:\n sort [3, 1, 1] = [1, 1, 3]\n end definition\nend law\n\nlaw \"|sorting orders values and keeps every occurrence| is\n definition:\n for all (xs :: List Int32) =>\n \"|is in ascending order| (sort xs) = true and sameItems (sort xs) xs\n end for all\n end definition\nend law\n\nend unit\n",
|
|
1221
|
+
"Harness.lawspec": "harness learn.sorting.testing for learn.sorting is\n strategy number :: (n :: Int32 where n >= -20 and n <= 20) is any end strategy\n\n -- Draw up to three items constructively; shrinking follows these choices.\n strategy lists :: List Int32 is\n bind a :: Int32 from number in\n bind b :: Int32 from number in\n bind c :: Int32 from number in\n one of [], [a], [a, b], [a, b, c]\n end bind end bind end bind\n end strategy\n\n for law \"|sorting orders values and keeps every occurrence|\n use lists for xs\n end for law\nend harness\n"
|
|
1222
|
+
},
|
|
1223
|
+
"javascript": {
|
|
1224
|
+
"Solution.js": "export function sort(xs)\n{\n return xs;\n}\n",
|
|
1225
|
+
"Tests.lawspec": "-- ref:DEC-learn-tests-in-lawspec\nunit learn.sorting\nsort :: List Int32 -> List Int32\n\nfunction \"|is in ascending order| (xs :: List Int32) -> Bool is\n first matching case of xs :\n when Nil then true\n when Cons h t then\n (first matching case of t :\n when Nil then true\n when Cons next rest then h <= next and \"|is in ascending order| t\n end case)\n end case\nend function\n\nlaw \"|an empty input stays empty| is\n definition:\n sort [] = []\n end definition\nend law\n\nlaw \"|sorting keeps repeated values| is\n definition:\n sort [3, 1, 1] = [1, 1, 3]\n end definition\nend law\n\nlaw \"|sorting orders values and keeps every occurrence| is\n definition:\n for all (xs :: List Int32) =>\n \"|is in ascending order| (sort xs) = true and sameItems (sort xs) xs\n end for all\n end definition\nend law\n\nend unit\n",
|
|
1226
|
+
"Harness.lawspec": "harness learn.sorting.testing for learn.sorting is\n strategy number :: (n :: Int32 where n >= -20 and n <= 20) is any end strategy\n\n -- Draw up to three items constructively; shrinking follows these choices.\n strategy lists :: List Int32 is\n bind a :: Int32 from number in\n bind b :: Int32 from number in\n bind c :: Int32 from number in\n one of [], [a], [a, b], [a, b, c]\n end bind end bind end bind\n end strategy\n\n for law \"|sorting orders values and keeps every occurrence|\n use lists for xs\n end for law\nend harness\n"
|
|
1227
|
+
}
|
|
1228
|
+
},
|
|
1229
|
+
"sources": {
|
|
1230
|
+
"fsharp": {
|
|
1231
|
+
"Tests.lawspec": "exercises/sorting/05/Tests.lawspec",
|
|
1232
|
+
"Harness.lawspec": "exercises/sorting/05/Harness.lawspec",
|
|
1233
|
+
"Solution.fs": "exercises/sorting/05/fsharp/Solution.fs"
|
|
1234
|
+
},
|
|
1235
|
+
"typescript": {
|
|
1236
|
+
"Tests.lawspec": "exercises/sorting/05/Tests.lawspec",
|
|
1237
|
+
"Harness.lawspec": "exercises/sorting/05/Harness.lawspec",
|
|
1238
|
+
"Solution.ts": "exercises/sorting/05/typescript/Solution.ts"
|
|
1239
|
+
},
|
|
1240
|
+
"javascript": {
|
|
1241
|
+
"Tests.lawspec": "exercises/sorting/05/Tests.lawspec",
|
|
1242
|
+
"Harness.lawspec": "exercises/sorting/05/Harness.lawspec",
|
|
1243
|
+
"Solution.js": "exercises/sorting/05/javascript/Solution.js"
|
|
1244
|
+
}
|
|
1245
|
+
},
|
|
1246
|
+
"previousProjects": {
|
|
1247
|
+
"fsharp": {
|
|
1248
|
+
"Solution.fs": "module Solution\n\nlet sort (xs: int list) : int list = xs\n",
|
|
1249
|
+
"Tests.lawspec": "-- ref:DEC-learn-tests-in-lawspec\nunit learn.sorting\nsort :: List Int32 -> List Int32\n\nfunction ordered (xs :: List Int32) -> Bool is\n first matching case of xs :\n when Nil then true\n when Cons h t then\n (first matching case of t :\n when Nil then true\n when Cons next rest then h <= next and ordered t\n end case)\n end case\nend function\n\nlaw emptyInput is\n definition:\n sort [] = []\n end definition\nend law\n\nlaw duplicateRequests is\n definition:\n sort [3, 1, 1] = [1, 1, 3]\n end definition\nend law\n\nlaw sortingRule is\n definition:\n for all (xs :: List Int32) => ordered (sort xs) = true and sameItems (sort\n xs) xs end for all\n end definition\nend law\n\nend unit\n",
|
|
1250
|
+
"Harness.lawspec": "harness learn.sorting.testing for learn.sorting is\n strategy number :: (n :: Int32 where n >= -20 and n <= 20) is any end strategy\n\n -- Draw up to three items constructively; shrinking follows these choices.\n strategy lists :: List Int32 is\n bind a :: Int32 from number in\n bind b :: Int32 from number in\n bind c :: Int32 from number in\n one of [], [a], [a, b], [a, b, c]\n end bind end bind end bind\n end strategy\n\n for law sortingRule\n use lists for xs\n end for law\nend harness\n"
|
|
1251
|
+
},
|
|
1252
|
+
"typescript": {
|
|
1253
|
+
"Solution.ts": "export function sort(xs: number[]): number[]\n{\n return xs;\n}\n",
|
|
1254
|
+
"Tests.lawspec": "-- ref:DEC-learn-tests-in-lawspec\nunit learn.sorting\nsort :: List Int32 -> List Int32\n\nfunction ordered (xs :: List Int32) -> Bool is\n first matching case of xs :\n when Nil then true\n when Cons h t then\n (first matching case of t :\n when Nil then true\n when Cons next rest then h <= next and ordered t\n end case)\n end case\nend function\n\nlaw emptyInput is\n definition:\n sort [] = []\n end definition\nend law\n\nlaw duplicateRequests is\n definition:\n sort [3, 1, 1] = [1, 1, 3]\n end definition\nend law\n\nlaw sortingRule is\n definition:\n for all (xs :: List Int32) => ordered (sort xs) = true and sameItems (sort\n xs) xs end for all\n end definition\nend law\n\nend unit\n",
|
|
1255
|
+
"Harness.lawspec": "harness learn.sorting.testing for learn.sorting is\n strategy number :: (n :: Int32 where n >= -20 and n <= 20) is any end strategy\n\n -- Draw up to three items constructively; shrinking follows these choices.\n strategy lists :: List Int32 is\n bind a :: Int32 from number in\n bind b :: Int32 from number in\n bind c :: Int32 from number in\n one of [], [a], [a, b], [a, b, c]\n end bind end bind end bind\n end strategy\n\n for law sortingRule\n use lists for xs\n end for law\nend harness\n"
|
|
1256
|
+
},
|
|
1257
|
+
"javascript": {
|
|
1258
|
+
"Solution.js": "export function sort(xs)\n{\n return xs;\n}\n",
|
|
1259
|
+
"Tests.lawspec": "-- ref:DEC-learn-tests-in-lawspec\nunit learn.sorting\nsort :: List Int32 -> List Int32\n\nfunction ordered (xs :: List Int32) -> Bool is\n first matching case of xs :\n when Nil then true\n when Cons h t then\n (first matching case of t :\n when Nil then true\n when Cons next rest then h <= next and ordered t\n end case)\n end case\nend function\n\nlaw emptyInput is\n definition:\n sort [] = []\n end definition\nend law\n\nlaw duplicateRequests is\n definition:\n sort [3, 1, 1] = [1, 1, 3]\n end definition\nend law\n\nlaw sortingRule is\n definition:\n for all (xs :: List Int32) => ordered (sort xs) = true and sameItems (sort\n xs) xs end for all\n end definition\nend law\n\nend unit\n",
|
|
1260
|
+
"Harness.lawspec": "harness learn.sorting.testing for learn.sorting is\n strategy number :: (n :: Int32 where n >= -20 and n <= 20) is any end strategy\n\n -- Draw up to three items constructively; shrinking follows these choices.\n strategy lists :: List Int32 is\n bind a :: Int32 from number in\n bind b :: Int32 from number in\n bind c :: Int32 from number in\n one of [], [a], [a, b], [a, b, c]\n end bind end bind end bind\n end strategy\n\n for law sortingRule\n use lists for xs\n end for law\nend harness\n"
|
|
1261
|
+
}
|
|
1262
|
+
}
|
|
1263
|
+
}
|
|
1264
|
+
],
|
|
1265
|
+
"solutionProject": "exercises/sorting/solution",
|
|
1266
|
+
"coverage": {
|
|
1267
|
+
"browserExecution": [
|
|
1268
|
+
"fsharp",
|
|
1269
|
+
"typescript",
|
|
1270
|
+
"javascript"
|
|
1271
|
+
],
|
|
1272
|
+
"definitionChecking": true,
|
|
1273
|
+
"nativeExecution": "deferred",
|
|
1274
|
+
"apiCollectionCredit": "deferred: this story is not a complete public API collection"
|
|
1275
|
+
},
|
|
1276
|
+
"implementationSyntax": {
|
|
1277
|
+
"fsharp": "In F#, int list is a list of integers; [] is empty. List.sort orders values; List.distinct removes repeated values. These are different operations.",
|
|
1278
|
+
"typescript": "In TypeScript, number[] is an array of numbers. A numeric sort needs a numeric comparator; new Set removes repeated values instead.",
|
|
1279
|
+
"javascript": "In JavaScript, [] is an empty array. A numeric sort needs a numeric comparator; new Set removes repeated values instead."
|
|
1280
|
+
},
|
|
1281
|
+
"naming": "Use English phrase names for readable claims and descriptive LawSpec helpers. Keep short code names such as add, sort, xs and numbers when they make calls and recipes easier to follow. A phrase starts with \"| and ends with |, without a closing quote. A law label identifies the claim; renaming it does not change what the definition checks. The compiler generates target-appropriate names.",
|
|
1282
|
+
"projects": {
|
|
1283
|
+
"fsharp": {
|
|
1284
|
+
"Solution.fs": "module Solution\n\nlet sort (xs: int list) : int list = []\n",
|
|
1285
|
+
"Tests.lawspec": "-- ref:DEC-learn-tests-in-lawspec\nunit learn.sorting\nsort :: List Int32 -> List Int32\n\nfunction \"|is in ascending order| (xs :: List Int32) -> Bool is\n first matching case of xs :\n when Nil then true\n when Cons h t then\n (first matching case of t :\n when Nil then true\n when Cons next rest then h <= next and \"|is in ascending order| t\n end case)\n end case\nend function\n\nlaw \"|an empty input stays empty| is\n definition:\n sort [] = []\n end definition\nend law\n\nlaw \"|the result is in ascending order| is\n definition:\n for all (xs :: List Int32) =>\n \"|is in ascending order| (sort xs) = true\n end for all\n end definition\nend law\n\nend unit\n",
|
|
1286
|
+
"Harness.lawspec": "harness learn.sorting.testing for learn.sorting is\n strategy number :: (n :: Int32 where n >= -20 and n <= 20) is any end strategy\n\n -- Draw up to three items constructively; shrinking follows these choices.\n strategy lists :: List Int32 is\n bind a :: Int32 from number in\n bind b :: Int32 from number in\n bind c :: Int32 from number in\n one of [], [a], [a, b], [a, b, c]\n end bind end bind end bind\n end strategy\n\n for law \"|the result is in ascending order|\n use lists for xs\n end for law\nend harness\n"
|
|
1287
|
+
},
|
|
1288
|
+
"typescript": {
|
|
1289
|
+
"Solution.ts": "export function sort(xs: number[]): number[]\n{\n return [];\n}\n",
|
|
1290
|
+
"Tests.lawspec": "-- ref:DEC-learn-tests-in-lawspec\nunit learn.sorting\nsort :: List Int32 -> List Int32\n\nfunction \"|is in ascending order| (xs :: List Int32) -> Bool is\n first matching case of xs :\n when Nil then true\n when Cons h t then\n (first matching case of t :\n when Nil then true\n when Cons next rest then h <= next and \"|is in ascending order| t\n end case)\n end case\nend function\n\nlaw \"|an empty input stays empty| is\n definition:\n sort [] = []\n end definition\nend law\n\nlaw \"|the result is in ascending order| is\n definition:\n for all (xs :: List Int32) =>\n \"|is in ascending order| (sort xs) = true\n end for all\n end definition\nend law\n\nend unit\n",
|
|
1291
|
+
"Harness.lawspec": "harness learn.sorting.testing for learn.sorting is\n strategy number :: (n :: Int32 where n >= -20 and n <= 20) is any end strategy\n\n -- Draw up to three items constructively; shrinking follows these choices.\n strategy lists :: List Int32 is\n bind a :: Int32 from number in\n bind b :: Int32 from number in\n bind c :: Int32 from number in\n one of [], [a], [a, b], [a, b, c]\n end bind end bind end bind\n end strategy\n\n for law \"|the result is in ascending order|\n use lists for xs\n end for law\nend harness\n"
|
|
1292
|
+
},
|
|
1293
|
+
"javascript": {
|
|
1294
|
+
"Solution.js": "export function sort(xs)\n{\n return [];\n}\n",
|
|
1295
|
+
"Tests.lawspec": "-- ref:DEC-learn-tests-in-lawspec\nunit learn.sorting\nsort :: List Int32 -> List Int32\n\nfunction \"|is in ascending order| (xs :: List Int32) -> Bool is\n first matching case of xs :\n when Nil then true\n when Cons h t then\n (first matching case of t :\n when Nil then true\n when Cons next rest then h <= next and \"|is in ascending order| t\n end case)\n end case\nend function\n\nlaw \"|an empty input stays empty| is\n definition:\n sort [] = []\n end definition\nend law\n\nlaw \"|the result is in ascending order| is\n definition:\n for all (xs :: List Int32) =>\n \"|is in ascending order| (sort xs) = true\n end for all\n end definition\nend law\n\nend unit\n",
|
|
1296
|
+
"Harness.lawspec": "harness learn.sorting.testing for learn.sorting is\n strategy number :: (n :: Int32 where n >= -20 and n <= 20) is any end strategy\n\n -- Draw up to three items constructively; shrinking follows these choices.\n strategy lists :: List Int32 is\n bind a :: Int32 from number in\n bind b :: Int32 from number in\n bind c :: Int32 from number in\n one of [], [a], [a, b], [a, b, c]\n end bind end bind end bind\n end strategy\n\n for law \"|the result is in ascending order|\n use lists for xs\n end for law\nend harness\n"
|
|
1297
|
+
}
|
|
1298
|
+
},
|
|
1299
|
+
"solutions": {
|
|
1300
|
+
"fsharp": {
|
|
1301
|
+
"Solution.fs": "module Solution\n\nlet sort (xs: int list) : int list = List.sort xs\n",
|
|
1302
|
+
"Tests.lawspec": "-- ref:DEC-learn-tests-in-lawspec\nunit learn.sorting\nsort :: List Int32 -> List Int32\n\nfunction \"|is in ascending order| (xs :: List Int32) -> Bool is\n first matching case of xs :\n when Nil then true\n when Cons h t then\n (first matching case of t :\n when Nil then true\n when Cons next rest then h <= next and \"|is in ascending order| t\n end case)\n end case\nend function\n\nlaw \"|an empty input stays empty| is\n definition:\n sort [] = []\n end definition\nend law\n\nlaw \"|sorting keeps repeated values| is\n definition:\n sort [3, 1, 1] = [1, 1, 3]\n end definition\nend law\n\nlaw \"|sorting orders values and keeps every occurrence| is\n definition:\n for all (xs :: List Int32) =>\n \"|is in ascending order| (sort xs) = true and sameItems (sort xs) xs\n end for all\n end definition\nend law\n\nend unit\n",
|
|
1303
|
+
"Harness.lawspec": "harness learn.sorting.testing for learn.sorting is\n strategy number :: (n :: Int32 where n >= -20 and n <= 20) is any end strategy\n\n -- Draw up to three items constructively; shrinking follows these choices.\n strategy lists :: List Int32 is\n bind a :: Int32 from number in\n bind b :: Int32 from number in\n bind c :: Int32 from number in\n one of [], [a], [a, b], [a, b, c]\n end bind end bind end bind\n end strategy\n\n for law \"|sorting orders values and keeps every occurrence|\n use lists for xs\n end for law\nend harness\n"
|
|
1304
|
+
},
|
|
1305
|
+
"typescript": {
|
|
1306
|
+
"Solution.ts": "export function sort(xs: number[]): number[]\n{\n return [...xs].sort((a, b) => a - b);\n}\n",
|
|
1307
|
+
"Tests.lawspec": "-- ref:DEC-learn-tests-in-lawspec\nunit learn.sorting\nsort :: List Int32 -> List Int32\n\nfunction \"|is in ascending order| (xs :: List Int32) -> Bool is\n first matching case of xs :\n when Nil then true\n when Cons h t then\n (first matching case of t :\n when Nil then true\n when Cons next rest then h <= next and \"|is in ascending order| t\n end case)\n end case\nend function\n\nlaw \"|an empty input stays empty| is\n definition:\n sort [] = []\n end definition\nend law\n\nlaw \"|sorting keeps repeated values| is\n definition:\n sort [3, 1, 1] = [1, 1, 3]\n end definition\nend law\n\nlaw \"|sorting orders values and keeps every occurrence| is\n definition:\n for all (xs :: List Int32) =>\n \"|is in ascending order| (sort xs) = true and sameItems (sort xs) xs\n end for all\n end definition\nend law\n\nend unit\n",
|
|
1308
|
+
"Harness.lawspec": "harness learn.sorting.testing for learn.sorting is\n strategy number :: (n :: Int32 where n >= -20 and n <= 20) is any end strategy\n\n -- Draw up to three items constructively; shrinking follows these choices.\n strategy lists :: List Int32 is\n bind a :: Int32 from number in\n bind b :: Int32 from number in\n bind c :: Int32 from number in\n one of [], [a], [a, b], [a, b, c]\n end bind end bind end bind\n end strategy\n\n for law \"|sorting orders values and keeps every occurrence|\n use lists for xs\n end for law\nend harness\n"
|
|
1309
|
+
},
|
|
1310
|
+
"javascript": {
|
|
1311
|
+
"Solution.js": "export function sort(xs)\n{\n return [...xs].sort((a, b) => a - b);\n}\n",
|
|
1312
|
+
"Tests.lawspec": "-- ref:DEC-learn-tests-in-lawspec\nunit learn.sorting\nsort :: List Int32 -> List Int32\n\nfunction \"|is in ascending order| (xs :: List Int32) -> Bool is\n first matching case of xs :\n when Nil then true\n when Cons h t then\n (first matching case of t :\n when Nil then true\n when Cons next rest then h <= next and \"|is in ascending order| t\n end case)\n end case\nend function\n\nlaw \"|an empty input stays empty| is\n definition:\n sort [] = []\n end definition\nend law\n\nlaw \"|sorting keeps repeated values| is\n definition:\n sort [3, 1, 1] = [1, 1, 3]\n end definition\nend law\n\nlaw \"|sorting orders values and keeps every occurrence| is\n definition:\n for all (xs :: List Int32) =>\n \"|is in ascending order| (sort xs) = true and sameItems (sort xs) xs\n end for all\n end definition\nend law\n\nend unit\n",
|
|
1313
|
+
"Harness.lawspec": "harness learn.sorting.testing for learn.sorting is\n strategy number :: (n :: Int32 where n >= -20 and n <= 20) is any end strategy\n\n -- Draw up to three items constructively; shrinking follows these choices.\n strategy lists :: List Int32 is\n bind a :: Int32 from number in\n bind b :: Int32 from number in\n bind c :: Int32 from number in\n one of [], [a], [a, b], [a, b, c]\n end bind end bind end bind\n end strategy\n\n for law \"|sorting orders values and keeps every occurrence|\n use lists for xs\n end for law\nend harness\n"
|
|
1314
|
+
}
|
|
1315
|
+
},
|
|
1316
|
+
"solutionSources": {
|
|
1317
|
+
"fsharp": {
|
|
1318
|
+
"Tests.lawspec": "exercises/sorting/solution/Tests.lawspec",
|
|
1319
|
+
"Harness.lawspec": "exercises/sorting/solution/Harness.lawspec",
|
|
1320
|
+
"Solution.fs": "exercises/sorting/solution/fsharp/Solution.fs"
|
|
1321
|
+
},
|
|
1322
|
+
"typescript": {
|
|
1323
|
+
"Tests.lawspec": "exercises/sorting/solution/Tests.lawspec",
|
|
1324
|
+
"Harness.lawspec": "exercises/sorting/solution/Harness.lawspec",
|
|
1325
|
+
"Solution.ts": "exercises/sorting/solution/typescript/Solution.ts"
|
|
1326
|
+
},
|
|
1327
|
+
"javascript": {
|
|
1328
|
+
"Tests.lawspec": "exercises/sorting/solution/Tests.lawspec",
|
|
1329
|
+
"Harness.lawspec": "exercises/sorting/solution/Harness.lawspec",
|
|
1330
|
+
"Solution.js": "exercises/sorting/solution/javascript/Solution.js"
|
|
1331
|
+
}
|
|
1332
|
+
}
|
|
1333
|
+
},
|
|
1334
|
+
{
|
|
1335
|
+
"id": "wlaschin-shrink",
|
|
1336
|
+
"title": "Find out why a passing sample misled us",
|
|
1337
|
+
"section": "Wlaschin’s examples",
|
|
1338
|
+
"vision": "Learn how input generation, shrinking and replay explain a false claim about a boundary.",
|
|
1339
|
+
"slogan": "Reach the boundary. Keep the failure.",
|
|
1340
|
+
"symbol": "79 < 80; 80 is not < 80",
|
|
1341
|
+
"explanation": "Laws and generation strategies are authored in LawSpec. Only the implementation changes language.",
|
|
1342
|
+
"news": "A generator can only expose failures among inputs it can reach.",
|
|
1343
|
+
"contributions": "A generator that reaches 80, an actual seed/path and shrink trace, a named boundary example, and a corrected classifier requirement. The passing correction retains the implementation and the wider generator.",
|
|
1344
|
+
"star": {
|
|
1345
|
+
"salient": "A generator can only expose failures among inputs it can reach.",
|
|
1346
|
+
"slogan": "Reach the boundary. Keep the failure.",
|
|
1347
|
+
"symbol": "79 < 80; 80 is not < 80",
|
|
1348
|
+
"surprise": "A false claim about 0–200 passes when every generated input is below 80.",
|
|
1349
|
+
"story": "An intentionally overbroad test passes on small inputs. Widening only the generator finds a failure, shrinking isolates 80, and the saved case helps correct the claim."
|
|
1350
|
+
},
|
|
1351
|
+
"attribution": [
|
|
1352
|
+
{
|
|
1353
|
+
"title": "Scott Wlaschin — Understanding FsCheck",
|
|
1354
|
+
"url": "https://fsharpforfunandprofit.com/posts/property-based-testing-1/",
|
|
1355
|
+
"use": "Adapted isSmallerThan80 example. The browser uses a uniform bounded generator and fast-check shrinking; it does not reproduce FsCheck’s distribution, seed or trace."
|
|
1356
|
+
}
|
|
1357
|
+
],
|
|
1358
|
+
"hints": [
|
|
1359
|
+
"At input 80, separately state the intended answer and the test’s expected answer.",
|
|
1360
|
+
"Check whether the harness can generate 80 before interpreting a passing sample.",
|
|
1361
|
+
"Keep the function’s strict comparison and make the claim describe both true and false answers. Load solution shows the corrected tests."
|
|
1362
|
+
],
|
|
1363
|
+
"stages": [
|
|
1364
|
+
{
|
|
1365
|
+
"id": "small",
|
|
1366
|
+
"title": "The test claims too much",
|
|
1367
|
+
"story": [
|
|
1368
|
+
"This is a small experiment in understanding a failed test. isSmallerThan80 answers one question: is this integer strictly below 80? At the end, you will be able to separate a false requirement from an implementation bug.",
|
|
1369
|
+
"The function is correct, but “every number from zero to two hundred is below eighty” in Laws claims its answer is true for every integer from 0 through 200. Pause at 80: what answer should the function give, and what answer does this claim demand?",
|
|
1370
|
+
"The harness is the test-data recipe, separate from the claim. Its numbers strategy chooses an integer; use numbers for n passes it to “every number from zero to two hundred is below eighty”. Open Harness: it only supplies 0 through 79.",
|
|
1371
|
+
"Run the sampled property. It passes because every sampled input is below 80. This mode excludes separate example/boundary checks; those may expose the false claim sooner. The pass describes the selected sample, not the whole 0–200 claim.",
|
|
1372
|
+
"A generator is a recipe for test data; LawSpec calls the named recipe a strategy. A sample is the collection of values actually tried in a run. Neither term means that every value in the stated domain was tested."
|
|
1373
|
+
],
|
|
1374
|
+
"focus": "Harness.lawspec",
|
|
1375
|
+
"project": "exercises/threshold/01",
|
|
1376
|
+
"run": {
|
|
1377
|
+
"mode": "sample",
|
|
1378
|
+
"expect": "passed",
|
|
1379
|
+
"sampled": "passed",
|
|
1380
|
+
"seed": 424242
|
|
1381
|
+
},
|
|
1382
|
+
"action": "Compare the law’s domain with the strategy’s bounds, then run the sampled property. Explain why its pass misses 80.",
|
|
1383
|
+
"reason": "A false claim can survive a test-data recipe that never reaches its counterexamples.",
|
|
1384
|
+
"expect": "The supplied code compiles and the selected checks pass. Read which checks actually ran before interpreting this result.",
|
|
1385
|
+
"recovery": "Reset this step restores its supplied files and seed. After an edit, use the actual result to judge your version; the story’s prediction describes the supplied files.",
|
|
1386
|
+
"syntax": "A property must evaluate to true to pass. “every number from zero to two hundred is below eighty” uses the classifier’s Boolean result directly. The law allows 0–200, while this strategy chooses only 0–79.",
|
|
1387
|
+
"editor": "Tests",
|
|
1388
|
+
"harnessNotes": [
|
|
1389
|
+
"numbers draws Int32 values from 0 through 79, including both endpoints. The binding for “every number from zero to two hundred is below eighty” names the claim in Laws, and use numbers for n feeds each draw into its quantified input n.",
|
|
1390
|
+
"The claim allows inputs up to 200, but this strategy never reaches 80. A sampled pass therefore misses the false part of the claim. Predict isSmallerThan80 80 before widening this recipe."
|
|
1391
|
+
],
|
|
1392
|
+
"symbol": "79 < 80; 80 is not < 80",
|
|
1393
|
+
"projects": {
|
|
1394
|
+
"fsharp": {
|
|
1395
|
+
"Solution.fs": "module Solution\n\nlet isSmallerThan80 (n: int) : bool = n < 80\n",
|
|
1396
|
+
"Tests.lawspec": "-- ref:DEC-learn-tests-in-lawspec\nunit learn.threshold\nisSmallerThan80 :: Int32 -> Bool\n\nlaw \"|seventy five is below eighty| is\n definition:\n isSmallerThan80 75 = true\n end definition\nend law\n\nlaw \"|every number from zero to two hundred is below eighty| is\n definition:\n for all (n :: Int32 where n >= 0 and n <= 200) =>\n isSmallerThan80 n = true\n end for all\n end definition\nend law\n\nend unit\n",
|
|
1397
|
+
"Harness.lawspec": "harness learn.threshold.testing for learn.threshold is\n strategy numbers :: (n :: Int32 where n >= 0 and n <= 79) is any end strategy\n for law \"|every number from zero to two hundred is below eighty|\n use numbers for n\n end for law\nend harness\n"
|
|
1398
|
+
},
|
|
1399
|
+
"typescript": {
|
|
1400
|
+
"Solution.ts": "export function isSmallerThan80(n: number): boolean\n{\n return n < 80;\n}\n",
|
|
1401
|
+
"Tests.lawspec": "-- ref:DEC-learn-tests-in-lawspec\nunit learn.threshold\nisSmallerThan80 :: Int32 -> Bool\n\nlaw \"|seventy five is below eighty| is\n definition:\n isSmallerThan80 75 = true\n end definition\nend law\n\nlaw \"|every number from zero to two hundred is below eighty| is\n definition:\n for all (n :: Int32 where n >= 0 and n <= 200) =>\n isSmallerThan80 n = true\n end for all\n end definition\nend law\n\nend unit\n",
|
|
1402
|
+
"Harness.lawspec": "harness learn.threshold.testing for learn.threshold is\n strategy numbers :: (n :: Int32 where n >= 0 and n <= 79) is any end strategy\n for law \"|every number from zero to two hundred is below eighty|\n use numbers for n\n end for law\nend harness\n"
|
|
1403
|
+
},
|
|
1404
|
+
"javascript": {
|
|
1405
|
+
"Solution.js": "export function isSmallerThan80(n)\n{\n return n < 80;\n}\n",
|
|
1406
|
+
"Tests.lawspec": "-- ref:DEC-learn-tests-in-lawspec\nunit learn.threshold\nisSmallerThan80 :: Int32 -> Bool\n\nlaw \"|seventy five is below eighty| is\n definition:\n isSmallerThan80 75 = true\n end definition\nend law\n\nlaw \"|every number from zero to two hundred is below eighty| is\n definition:\n for all (n :: Int32 where n >= 0 and n <= 200) =>\n isSmallerThan80 n = true\n end for all\n end definition\nend law\n\nend unit\n",
|
|
1407
|
+
"Harness.lawspec": "harness learn.threshold.testing for learn.threshold is\n strategy numbers :: (n :: Int32 where n >= 0 and n <= 79) is any end strategy\n for law \"|every number from zero to two hundred is below eighty|\n use numbers for n\n end for law\nend harness\n"
|
|
1408
|
+
}
|
|
1409
|
+
},
|
|
1410
|
+
"sources": {
|
|
1411
|
+
"fsharp": {
|
|
1412
|
+
"Tests.lawspec": "exercises/threshold/01/Tests.lawspec",
|
|
1413
|
+
"Harness.lawspec": "exercises/threshold/01/Harness.lawspec",
|
|
1414
|
+
"Solution.fs": "exercises/threshold/01/fsharp/Solution.fs"
|
|
1415
|
+
},
|
|
1416
|
+
"typescript": {
|
|
1417
|
+
"Tests.lawspec": "exercises/threshold/01/Tests.lawspec",
|
|
1418
|
+
"Harness.lawspec": "exercises/threshold/01/Harness.lawspec",
|
|
1419
|
+
"Solution.ts": "exercises/threshold/01/typescript/Solution.ts"
|
|
1420
|
+
},
|
|
1421
|
+
"javascript": {
|
|
1422
|
+
"Tests.lawspec": "exercises/threshold/01/Tests.lawspec",
|
|
1423
|
+
"Harness.lawspec": "exercises/threshold/01/Harness.lawspec",
|
|
1424
|
+
"Solution.js": "exercises/threshold/01/javascript/Solution.js"
|
|
1425
|
+
}
|
|
1426
|
+
},
|
|
1427
|
+
"previousProjects": {
|
|
1428
|
+
"fsharp": {
|
|
1429
|
+
"Solution.fs": "module Solution\n\nlet isSmallerThan80 (n: int) : bool = n < 80\n",
|
|
1430
|
+
"Tests.lawspec": "-- ref:DEC-learn-tests-in-lawspec\nunit learn.threshold\nisSmallerThan80 :: Int32 -> Bool\n\nlaw seventyFive is\n definition:\n isSmallerThan80 75 = true\n end definition\nend law\n\nlaw everythingBelow80 is\n definition:\n for all (n :: Int32 where n >= 0 and n <= 200) => isSmallerThan80 n = true\n end for all\n end definition\nend law\n\nend unit\n",
|
|
1431
|
+
"Harness.lawspec": "harness learn.threshold.testing for learn.threshold is\n strategy numbers :: (n :: Int32 where n >= 0 and n <= 79) is any end strategy\n for law everythingBelow80\n use numbers for n\n end for law\nend harness\n"
|
|
1432
|
+
},
|
|
1433
|
+
"typescript": {
|
|
1434
|
+
"Solution.ts": "export function isSmallerThan80(n: number): boolean\n{\n return n < 80;\n}\n",
|
|
1435
|
+
"Tests.lawspec": "-- ref:DEC-learn-tests-in-lawspec\nunit learn.threshold\nisSmallerThan80 :: Int32 -> Bool\n\nlaw seventyFive is\n definition:\n isSmallerThan80 75 = true\n end definition\nend law\n\nlaw everythingBelow80 is\n definition:\n for all (n :: Int32 where n >= 0 and n <= 200) => isSmallerThan80 n = true\n end for all\n end definition\nend law\n\nend unit\n",
|
|
1436
|
+
"Harness.lawspec": "harness learn.threshold.testing for learn.threshold is\n strategy numbers :: (n :: Int32 where n >= 0 and n <= 79) is any end strategy\n for law everythingBelow80\n use numbers for n\n end for law\nend harness\n"
|
|
1437
|
+
},
|
|
1438
|
+
"javascript": {
|
|
1439
|
+
"Solution.js": "export function isSmallerThan80(n)\n{\n return n < 80;\n}\n",
|
|
1440
|
+
"Tests.lawspec": "-- ref:DEC-learn-tests-in-lawspec\nunit learn.threshold\nisSmallerThan80 :: Int32 -> Bool\n\nlaw seventyFive is\n definition:\n isSmallerThan80 75 = true\n end definition\nend law\n\nlaw everythingBelow80 is\n definition:\n for all (n :: Int32 where n >= 0 and n <= 200) => isSmallerThan80 n = true\n end for all\n end definition\nend law\n\nend unit\n",
|
|
1441
|
+
"Harness.lawspec": "harness learn.threshold.testing for learn.threshold is\n strategy numbers :: (n :: Int32 where n >= 0 and n <= 79) is any end strategy\n for law everythingBelow80\n use numbers for n\n end for law\nend harness\n"
|
|
1442
|
+
}
|
|
1443
|
+
}
|
|
1444
|
+
},
|
|
1445
|
+
{
|
|
1446
|
+
"id": "widen",
|
|
1447
|
+
"title": "Change only the test-data recipe",
|
|
1448
|
+
"story": [
|
|
1449
|
+
"Harness now permits values from 0 through 200. The function and the false claim are unchanged. This one change lets the runner try values at and above 80.",
|
|
1450
|
+
"A counterexample is an input that makes a claim false. Shrinking is the runner’s search for a smaller input that still makes it false. Smaller means simpler for this recipe, not a guarantee of the smallest possible failure in every ordering.",
|
|
1451
|
+
"Run with seed 424242. Inspect the actual failing input and shrink attempts. Shrinking tries smaller candidates and retains candidates that still fail the same claim. This run ends at 80: 79 would pass, so it cannot explain this failure.",
|
|
1452
|
+
"Use Replay failure before editing. The recorded seed and path reproduce this failing case under the same source, generator and tool versions. The displayed trace comes from this browser run, not from Wlaschin’s FsCheck trace.",
|
|
1453
|
+
"A seed selects a repeatable sequence of generated choices. The replay path records the choices leading to the failing case. Keep the same source and generator when replaying; changing them creates a different experiment."
|
|
1454
|
+
],
|
|
1455
|
+
"focus": "Harness.lawspec",
|
|
1456
|
+
"project": "exercises/threshold/02",
|
|
1457
|
+
"run": {
|
|
1458
|
+
"mode": "sample",
|
|
1459
|
+
"expect": "failed",
|
|
1460
|
+
"sampled": "failed",
|
|
1461
|
+
"counterexample": [
|
|
1462
|
+
80
|
|
1463
|
+
],
|
|
1464
|
+
"minShrinks": 1,
|
|
1465
|
+
"seed": 424242
|
|
1466
|
+
},
|
|
1467
|
+
"action": "Run the wider sample, inspect its shrink trace and replay the failure. Explain why 80 fails and 79 does not.",
|
|
1468
|
+
"reason": "A small counterexample makes the disagreement between requirement and behavior easier to inspect.",
|
|
1469
|
+
"expect": "The supplied code compiles, then the selected checks fail. A compiler error is a different problem; inspect diagnostics if execution did not start.",
|
|
1470
|
+
"recovery": "Reset this step restores its supplied files and seed. After an edit, use the actual result to judge your version; the story’s prediction describes the supplied files.",
|
|
1471
|
+
"regression": {
|
|
1472
|
+
"input": 80,
|
|
1473
|
+
"expected": true
|
|
1474
|
+
},
|
|
1475
|
+
"editor": "Tests",
|
|
1476
|
+
"syntax": "The strategy’s upper bound changed to 200. It changes which inputs can be tried; it does not change the Boolean expression in the law.",
|
|
1477
|
+
"harnessNotes": [
|
|
1478
|
+
"numbers draws Int32 values from 0 through 200, including both endpoints. The binding for “every number from zero to two hundred is below eighty” names the claim in Laws, and use numbers for n feeds each draw into its quantified input n.",
|
|
1479
|
+
"The wider recipe can reach 80 and values above it. Shrinking retries smaller candidates against the same law and keeps a candidate only when it still fails. In this seeded example, 80 is the final failing input; the generator alone does not decide what counts as a failure."
|
|
1480
|
+
],
|
|
1481
|
+
"projects": {
|
|
1482
|
+
"fsharp": {
|
|
1483
|
+
"Solution.fs": "module Solution\n\nlet isSmallerThan80 (n: int) : bool = n < 80\n",
|
|
1484
|
+
"Tests.lawspec": "-- ref:DEC-learn-tests-in-lawspec\nunit learn.threshold\nisSmallerThan80 :: Int32 -> Bool\n\nlaw \"|seventy five is below eighty| is\n definition:\n isSmallerThan80 75 = true\n end definition\nend law\n\nlaw \"|every number from zero to two hundred is below eighty| is\n definition:\n for all (n :: Int32 where n >= 0 and n <= 200) =>\n isSmallerThan80 n = true\n end for all\n end definition\nend law\n\nend unit\n",
|
|
1485
|
+
"Harness.lawspec": "harness learn.threshold.testing for learn.threshold is\n strategy numbers :: (n :: Int32 where n >= 0 and n <= 200) is any end strategy\n for law \"|every number from zero to two hundred is below eighty|\n use numbers for n\n end for law\nend harness\n"
|
|
1486
|
+
},
|
|
1487
|
+
"typescript": {
|
|
1488
|
+
"Solution.ts": "export function isSmallerThan80(n: number): boolean\n{\n return n < 80;\n}\n",
|
|
1489
|
+
"Tests.lawspec": "-- ref:DEC-learn-tests-in-lawspec\nunit learn.threshold\nisSmallerThan80 :: Int32 -> Bool\n\nlaw \"|seventy five is below eighty| is\n definition:\n isSmallerThan80 75 = true\n end definition\nend law\n\nlaw \"|every number from zero to two hundred is below eighty| is\n definition:\n for all (n :: Int32 where n >= 0 and n <= 200) =>\n isSmallerThan80 n = true\n end for all\n end definition\nend law\n\nend unit\n",
|
|
1490
|
+
"Harness.lawspec": "harness learn.threshold.testing for learn.threshold is\n strategy numbers :: (n :: Int32 where n >= 0 and n <= 200) is any end strategy\n for law \"|every number from zero to two hundred is below eighty|\n use numbers for n\n end for law\nend harness\n"
|
|
1491
|
+
},
|
|
1492
|
+
"javascript": {
|
|
1493
|
+
"Solution.js": "export function isSmallerThan80(n)\n{\n return n < 80;\n}\n",
|
|
1494
|
+
"Tests.lawspec": "-- ref:DEC-learn-tests-in-lawspec\nunit learn.threshold\nisSmallerThan80 :: Int32 -> Bool\n\nlaw \"|seventy five is below eighty| is\n definition:\n isSmallerThan80 75 = true\n end definition\nend law\n\nlaw \"|every number from zero to two hundred is below eighty| is\n definition:\n for all (n :: Int32 where n >= 0 and n <= 200) =>\n isSmallerThan80 n = true\n end for all\n end definition\nend law\n\nend unit\n",
|
|
1495
|
+
"Harness.lawspec": "harness learn.threshold.testing for learn.threshold is\n strategy numbers :: (n :: Int32 where n >= 0 and n <= 200) is any end strategy\n for law \"|every number from zero to two hundred is below eighty|\n use numbers for n\n end for law\nend harness\n"
|
|
1496
|
+
}
|
|
1497
|
+
},
|
|
1498
|
+
"sources": {
|
|
1499
|
+
"fsharp": {
|
|
1500
|
+
"Tests.lawspec": "exercises/threshold/02/Tests.lawspec",
|
|
1501
|
+
"Harness.lawspec": "exercises/threshold/02/Harness.lawspec",
|
|
1502
|
+
"Solution.fs": "exercises/threshold/01/fsharp/Solution.fs"
|
|
1503
|
+
},
|
|
1504
|
+
"typescript": {
|
|
1505
|
+
"Tests.lawspec": "exercises/threshold/02/Tests.lawspec",
|
|
1506
|
+
"Harness.lawspec": "exercises/threshold/02/Harness.lawspec",
|
|
1507
|
+
"Solution.ts": "exercises/threshold/01/typescript/Solution.ts"
|
|
1508
|
+
},
|
|
1509
|
+
"javascript": {
|
|
1510
|
+
"Tests.lawspec": "exercises/threshold/02/Tests.lawspec",
|
|
1511
|
+
"Harness.lawspec": "exercises/threshold/02/Harness.lawspec",
|
|
1512
|
+
"Solution.js": "exercises/threshold/01/javascript/Solution.js"
|
|
1513
|
+
}
|
|
1514
|
+
},
|
|
1515
|
+
"previousProjects": {
|
|
1516
|
+
"fsharp": {
|
|
1517
|
+
"Solution.fs": "module Solution\n\nlet isSmallerThan80 (n: int) : bool = n < 80\n",
|
|
1518
|
+
"Tests.lawspec": "-- ref:DEC-learn-tests-in-lawspec\nunit learn.threshold\nisSmallerThan80 :: Int32 -> Bool\n\nlaw seventyFive is\n definition:\n isSmallerThan80 75 = true\n end definition\nend law\n\nlaw everythingBelow80 is\n definition:\n for all (n :: Int32 where n >= 0 and n <= 200) => isSmallerThan80 n = true\n end for all\n end definition\nend law\n\nend unit\n",
|
|
1519
|
+
"Harness.lawspec": "harness learn.threshold.testing for learn.threshold is\n strategy numbers :: (n :: Int32 where n >= 0 and n <= 200) is any end strategy\n for law everythingBelow80\n use numbers for n\n end for law\nend harness\n"
|
|
1520
|
+
},
|
|
1521
|
+
"typescript": {
|
|
1522
|
+
"Solution.ts": "export function isSmallerThan80(n: number): boolean\n{\n return n < 80;\n}\n",
|
|
1523
|
+
"Tests.lawspec": "-- ref:DEC-learn-tests-in-lawspec\nunit learn.threshold\nisSmallerThan80 :: Int32 -> Bool\n\nlaw seventyFive is\n definition:\n isSmallerThan80 75 = true\n end definition\nend law\n\nlaw everythingBelow80 is\n definition:\n for all (n :: Int32 where n >= 0 and n <= 200) => isSmallerThan80 n = true\n end for all\n end definition\nend law\n\nend unit\n",
|
|
1524
|
+
"Harness.lawspec": "harness learn.threshold.testing for learn.threshold is\n strategy numbers :: (n :: Int32 where n >= 0 and n <= 200) is any end strategy\n for law everythingBelow80\n use numbers for n\n end for law\nend harness\n"
|
|
1525
|
+
},
|
|
1526
|
+
"javascript": {
|
|
1527
|
+
"Solution.js": "export function isSmallerThan80(n)\n{\n return n < 80;\n}\n",
|
|
1528
|
+
"Tests.lawspec": "-- ref:DEC-learn-tests-in-lawspec\nunit learn.threshold\nisSmallerThan80 :: Int32 -> Bool\n\nlaw seventyFive is\n definition:\n isSmallerThan80 75 = true\n end definition\nend law\n\nlaw everythingBelow80 is\n definition:\n for all (n :: Int32 where n >= 0 and n <= 200) => isSmallerThan80 n = true\n end for all\n end definition\nend law\n\nend unit\n",
|
|
1529
|
+
"Harness.lawspec": "harness learn.threshold.testing for learn.threshold is\n strategy numbers :: (n :: Int32 where n >= 0 and n <= 200) is any end strategy\n for law everythingBelow80\n use numbers for n\n end for law\nend harness\n"
|
|
1530
|
+
}
|
|
1531
|
+
}
|
|
1532
|
+
},
|
|
1533
|
+
{
|
|
1534
|
+
"id": "regression",
|
|
1535
|
+
"title": "Write down the disagreement",
|
|
1536
|
+
"story": [
|
|
1537
|
+
"A regression case is a previously discovered failure kept as an ordinary example. It helps catch the same disagreement again without waiting for random generation. Save regression writes that example into Laws, and progress backups include it.",
|
|
1538
|
+
"Laws now records 80 as “eighty should be below eighty”. It asks the same question as the old claim: isSmallerThan80 80 should be true.",
|
|
1539
|
+
"Use Run checks with Examples + boundaries. The named check fails without depending on random generation. Read the function and the test side by side: the function correctly answers false. Here the test’s expected answer is the mistake.",
|
|
1540
|
+
"Saving a counterexample preserves the disagreement. It does not tell us which side is right; we still have to interpret the intended requirement."
|
|
1541
|
+
],
|
|
1542
|
+
"focus": "Tests",
|
|
1543
|
+
"project": "exercises/threshold/03",
|
|
1544
|
+
"run": {
|
|
1545
|
+
"mode": "examples",
|
|
1546
|
+
"expect": "failed",
|
|
1547
|
+
"failedTests": [
|
|
1548
|
+
"learn.threshold::|eighty should be below eighty| boundary 1"
|
|
1549
|
+
],
|
|
1550
|
+
"seed": 424242
|
|
1551
|
+
},
|
|
1552
|
+
"action": "Use Run checks with Examples + boundaries and locate “eighty should be below eighty”. State which answer the function should give before choosing what to repair.",
|
|
1553
|
+
"reason": "A failure is a disagreement to investigate, not an automatic instruction to change the implementation.",
|
|
1554
|
+
"expect": "The supplied code compiles, then the selected checks fail. A compiler error is a different problem; inspect diagnostics if execution did not start.",
|
|
1555
|
+
"recovery": "Reset this step restores its supplied files and seed. After an edit, use the actual result to judge your version; the story’s prediction describes the supplied files.",
|
|
1556
|
+
"editor": "Solution",
|
|
1557
|
+
"syntax": "“eighty should be below eighty” is a concrete claim at one input. It no longer needs a generator to reproduce the mismatch.",
|
|
1558
|
+
"harnessNotes": [
|
|
1559
|
+
"numbers draws Int32 values from 0 through 200, including both endpoints. The binding for “every number from zero to two hundred is below eighty” names the claim in Laws, and use numbers for n feeds each draw into its quantified input n.",
|
|
1560
|
+
"The wider recipe can reach 80 and values above it. Shrinking retries smaller candidates against the same law and keeps a candidate only when it still fails. In this seeded example, 80 is the final failing input; the generator alone does not decide what counts as a failure."
|
|
1561
|
+
],
|
|
1562
|
+
"projects": {
|
|
1563
|
+
"fsharp": {
|
|
1564
|
+
"Solution.fs": "module Solution\n\nlet isSmallerThan80 (n: int) : bool = n < 80\n",
|
|
1565
|
+
"Tests.lawspec": "-- ref:DEC-learn-tests-in-lawspec\nunit learn.threshold\nisSmallerThan80 :: Int32 -> Bool\n\nlaw \"|seventy five is below eighty| is\n definition:\n isSmallerThan80 75 = true\n end definition\nend law\n\nlaw \"|eighty should be below eighty| is\n definition:\n isSmallerThan80 80 = true\n end definition\nend law\n\nlaw \"|every number from zero to two hundred is below eighty| is\n definition:\n for all (n :: Int32 where n >= 0 and n <= 200) =>\n isSmallerThan80 n = true\n end for all\n end definition\nend law\n\nend unit\n",
|
|
1566
|
+
"Harness.lawspec": "harness learn.threshold.testing for learn.threshold is\n strategy numbers :: (n :: Int32 where n >= 0 and n <= 200) is any end strategy\n for law \"|every number from zero to two hundred is below eighty|\n use numbers for n\n end for law\nend harness\n"
|
|
1567
|
+
},
|
|
1568
|
+
"typescript": {
|
|
1569
|
+
"Solution.ts": "export function isSmallerThan80(n: number): boolean\n{\n return n < 80;\n}\n",
|
|
1570
|
+
"Tests.lawspec": "-- ref:DEC-learn-tests-in-lawspec\nunit learn.threshold\nisSmallerThan80 :: Int32 -> Bool\n\nlaw \"|seventy five is below eighty| is\n definition:\n isSmallerThan80 75 = true\n end definition\nend law\n\nlaw \"|eighty should be below eighty| is\n definition:\n isSmallerThan80 80 = true\n end definition\nend law\n\nlaw \"|every number from zero to two hundred is below eighty| is\n definition:\n for all (n :: Int32 where n >= 0 and n <= 200) =>\n isSmallerThan80 n = true\n end for all\n end definition\nend law\n\nend unit\n",
|
|
1571
|
+
"Harness.lawspec": "harness learn.threshold.testing for learn.threshold is\n strategy numbers :: (n :: Int32 where n >= 0 and n <= 200) is any end strategy\n for law \"|every number from zero to two hundred is below eighty|\n use numbers for n\n end for law\nend harness\n"
|
|
1572
|
+
},
|
|
1573
|
+
"javascript": {
|
|
1574
|
+
"Solution.js": "export function isSmallerThan80(n)\n{\n return n < 80;\n}\n",
|
|
1575
|
+
"Tests.lawspec": "-- ref:DEC-learn-tests-in-lawspec\nunit learn.threshold\nisSmallerThan80 :: Int32 -> Bool\n\nlaw \"|seventy five is below eighty| is\n definition:\n isSmallerThan80 75 = true\n end definition\nend law\n\nlaw \"|eighty should be below eighty| is\n definition:\n isSmallerThan80 80 = true\n end definition\nend law\n\nlaw \"|every number from zero to two hundred is below eighty| is\n definition:\n for all (n :: Int32 where n >= 0 and n <= 200) =>\n isSmallerThan80 n = true\n end for all\n end definition\nend law\n\nend unit\n",
|
|
1576
|
+
"Harness.lawspec": "harness learn.threshold.testing for learn.threshold is\n strategy numbers :: (n :: Int32 where n >= 0 and n <= 200) is any end strategy\n for law \"|every number from zero to two hundred is below eighty|\n use numbers for n\n end for law\nend harness\n"
|
|
1577
|
+
}
|
|
1578
|
+
},
|
|
1579
|
+
"sources": {
|
|
1580
|
+
"fsharp": {
|
|
1581
|
+
"Tests.lawspec": "exercises/threshold/03/Tests.lawspec",
|
|
1582
|
+
"Harness.lawspec": "exercises/threshold/03/Harness.lawspec",
|
|
1583
|
+
"Solution.fs": "exercises/threshold/01/fsharp/Solution.fs"
|
|
1584
|
+
},
|
|
1585
|
+
"typescript": {
|
|
1586
|
+
"Tests.lawspec": "exercises/threshold/03/Tests.lawspec",
|
|
1587
|
+
"Harness.lawspec": "exercises/threshold/03/Harness.lawspec",
|
|
1588
|
+
"Solution.ts": "exercises/threshold/01/typescript/Solution.ts"
|
|
1589
|
+
},
|
|
1590
|
+
"javascript": {
|
|
1591
|
+
"Tests.lawspec": "exercises/threshold/03/Tests.lawspec",
|
|
1592
|
+
"Harness.lawspec": "exercises/threshold/03/Harness.lawspec",
|
|
1593
|
+
"Solution.js": "exercises/threshold/01/javascript/Solution.js"
|
|
1594
|
+
}
|
|
1595
|
+
},
|
|
1596
|
+
"previousProjects": {
|
|
1597
|
+
"fsharp": {
|
|
1598
|
+
"Solution.fs": "module Solution\n\nlet isSmallerThan80 (n: int) : bool = n < 80\n",
|
|
1599
|
+
"Tests.lawspec": "-- ref:DEC-learn-tests-in-lawspec\nunit learn.threshold\nisSmallerThan80 :: Int32 -> Bool\n\nlaw seventyFive is\n definition:\n isSmallerThan80 75 = true\n end definition\nend law\n\nlaw savedBoundary is\n definition:\n isSmallerThan80 80 = true\n end definition\nend law\n\nlaw everythingBelow80 is\n definition:\n for all (n :: Int32 where n >= 0 and n <= 200) => isSmallerThan80 n = true\n end for all\n end definition\nend law\n\nend unit\n",
|
|
1600
|
+
"Harness.lawspec": "harness learn.threshold.testing for learn.threshold is\n strategy numbers :: (n :: Int32 where n >= 0 and n <= 200) is any end strategy\n for law everythingBelow80\n use numbers for n\n end for law\nend harness\n"
|
|
1601
|
+
},
|
|
1602
|
+
"typescript": {
|
|
1603
|
+
"Solution.ts": "export function isSmallerThan80(n: number): boolean\n{\n return n < 80;\n}\n",
|
|
1604
|
+
"Tests.lawspec": "-- ref:DEC-learn-tests-in-lawspec\nunit learn.threshold\nisSmallerThan80 :: Int32 -> Bool\n\nlaw seventyFive is\n definition:\n isSmallerThan80 75 = true\n end definition\nend law\n\nlaw savedBoundary is\n definition:\n isSmallerThan80 80 = true\n end definition\nend law\n\nlaw everythingBelow80 is\n definition:\n for all (n :: Int32 where n >= 0 and n <= 200) => isSmallerThan80 n = true\n end for all\n end definition\nend law\n\nend unit\n",
|
|
1605
|
+
"Harness.lawspec": "harness learn.threshold.testing for learn.threshold is\n strategy numbers :: (n :: Int32 where n >= 0 and n <= 200) is any end strategy\n for law everythingBelow80\n use numbers for n\n end for law\nend harness\n"
|
|
1606
|
+
},
|
|
1607
|
+
"javascript": {
|
|
1608
|
+
"Solution.js": "export function isSmallerThan80(n)\n{\n return n < 80;\n}\n",
|
|
1609
|
+
"Tests.lawspec": "-- ref:DEC-learn-tests-in-lawspec\nunit learn.threshold\nisSmallerThan80 :: Int32 -> Bool\n\nlaw seventyFive is\n definition:\n isSmallerThan80 75 = true\n end definition\nend law\n\nlaw savedBoundary is\n definition:\n isSmallerThan80 80 = true\n end definition\nend law\n\nlaw everythingBelow80 is\n definition:\n for all (n :: Int32 where n >= 0 and n <= 200) => isSmallerThan80 n = true\n end for all\n end definition\nend law\n\nend unit\n",
|
|
1610
|
+
"Harness.lawspec": "harness learn.threshold.testing for learn.threshold is\n strategy numbers :: (n :: Int32 where n >= 0 and n <= 200) is any end strategy\n for law everythingBelow80\n use numbers for n\n end for law\nend harness\n"
|
|
1611
|
+
}
|
|
1612
|
+
}
|
|
1613
|
+
},
|
|
1614
|
+
{
|
|
1615
|
+
"id": "correct-claim",
|
|
1616
|
+
"title": "Repair the claim and keep the wider inputs",
|
|
1617
|
+
"story": [
|
|
1618
|
+
"The function is unchanged. “the answer agrees with being below eighty” now requires its answer to agree with n < 80. The named examples expect true at 79 and false at 80.",
|
|
1619
|
+
"Use Run checks with All checks. The corrected claim passes while the generator still reaches both sides of the boundary. We did not make the test green by excluding inconvenient inputs.",
|
|
1620
|
+
"Your challenge: change the function’s comparison from < to <= and rerun. Explain why the example at 80 rejects that edit, then restore <. You have now used a failure to repair a claim, and used the corrected claim to catch an implementation bug."
|
|
1621
|
+
],
|
|
1622
|
+
"focus": "Tests",
|
|
1623
|
+
"project": "exercises/threshold/solution",
|
|
1624
|
+
"run": {
|
|
1625
|
+
"mode": "all",
|
|
1626
|
+
"expect": "passed",
|
|
1627
|
+
"sampled": "passed",
|
|
1628
|
+
"seed": 424242
|
|
1629
|
+
},
|
|
1630
|
+
"action": "Run the corrected suite, try the <= mistake and explain its failure at 80, then restore the correct comparison.",
|
|
1631
|
+
"reason": "Reach the boundary. Keep the failure. Preserve the lesson learned when you repair the test.",
|
|
1632
|
+
"expect": "The supplied code compiles and the selected checks pass. Read which checks actually ran before interpreting this result.",
|
|
1633
|
+
"recovery": "Reset this step restores its supplied files and seed. After an edit, use the actual result to judge your version; the story’s prediction describes the supplied files.",
|
|
1634
|
+
"challenge": true,
|
|
1635
|
+
"editor": "Solution",
|
|
1636
|
+
"syntax": "n < 80 is a Boolean expression. The corrected property compares that expected answer with the function’s actual answer instead of assuming every answer is true.",
|
|
1637
|
+
"harnessNotes": [
|
|
1638
|
+
"numbers draws Int32 values from 0 through 200, including both endpoints. The binding for “the answer agrees with being below eighty” names the claim in Laws, and use numbers for n feeds each draw into its quantified input n.",
|
|
1639
|
+
"This keeps the wider recipe and binds it to the corrected “the answer agrees with being below eighty” claim. Inputs above 79 still occur; the corrected law now checks that the classifier agrees with n < 80."
|
|
1640
|
+
],
|
|
1641
|
+
"projects": {
|
|
1642
|
+
"fsharp": {
|
|
1643
|
+
"Solution.fs": "module Solution\n\nlet isSmallerThan80 (n: int) : bool = n < 80\n",
|
|
1644
|
+
"Tests.lawspec": "-- ref:DEC-learn-tests-in-lawspec\nunit learn.threshold\nisSmallerThan80 :: Int32 -> Bool\n\nlaw \"|seventy five is below eighty| is\n definition:\n isSmallerThan80 75 = true\n end definition\nend law\n\nlaw \"|seventy nine is below eighty| is\n definition:\n isSmallerThan80 79 = true\n end definition\nend law\n\nlaw \"|eighty is not below eighty| is\n definition:\n isSmallerThan80 80 = false\n end definition\nend law\n\nlaw \"|the answer agrees with being below eighty| is\n definition:\n for all (n :: Int32 where n >= 0 and n <= 200) =>\n isSmallerThan80 n = (n < 80)\n end for all\n end definition\nend law\n\nend unit\n",
|
|
1645
|
+
"Harness.lawspec": "harness learn.threshold.testing for learn.threshold is\n strategy numbers :: (n :: Int32 where n >= 0 and n <= 200) is any end strategy\n for law \"|the answer agrees with being below eighty|\n use numbers for n\n end for law\nend harness\n"
|
|
1646
|
+
},
|
|
1647
|
+
"typescript": {
|
|
1648
|
+
"Solution.ts": "export function isSmallerThan80(n: number): boolean\n{\n return n < 80;\n}\n",
|
|
1649
|
+
"Tests.lawspec": "-- ref:DEC-learn-tests-in-lawspec\nunit learn.threshold\nisSmallerThan80 :: Int32 -> Bool\n\nlaw \"|seventy five is below eighty| is\n definition:\n isSmallerThan80 75 = true\n end definition\nend law\n\nlaw \"|seventy nine is below eighty| is\n definition:\n isSmallerThan80 79 = true\n end definition\nend law\n\nlaw \"|eighty is not below eighty| is\n definition:\n isSmallerThan80 80 = false\n end definition\nend law\n\nlaw \"|the answer agrees with being below eighty| is\n definition:\n for all (n :: Int32 where n >= 0 and n <= 200) =>\n isSmallerThan80 n = (n < 80)\n end for all\n end definition\nend law\n\nend unit\n",
|
|
1650
|
+
"Harness.lawspec": "harness learn.threshold.testing for learn.threshold is\n strategy numbers :: (n :: Int32 where n >= 0 and n <= 200) is any end strategy\n for law \"|the answer agrees with being below eighty|\n use numbers for n\n end for law\nend harness\n"
|
|
1651
|
+
},
|
|
1652
|
+
"javascript": {
|
|
1653
|
+
"Solution.js": "export function isSmallerThan80(n)\n{\n return n < 80;\n}\n",
|
|
1654
|
+
"Tests.lawspec": "-- ref:DEC-learn-tests-in-lawspec\nunit learn.threshold\nisSmallerThan80 :: Int32 -> Bool\n\nlaw \"|seventy five is below eighty| is\n definition:\n isSmallerThan80 75 = true\n end definition\nend law\n\nlaw \"|seventy nine is below eighty| is\n definition:\n isSmallerThan80 79 = true\n end definition\nend law\n\nlaw \"|eighty is not below eighty| is\n definition:\n isSmallerThan80 80 = false\n end definition\nend law\n\nlaw \"|the answer agrees with being below eighty| is\n definition:\n for all (n :: Int32 where n >= 0 and n <= 200) =>\n isSmallerThan80 n = (n < 80)\n end for all\n end definition\nend law\n\nend unit\n",
|
|
1655
|
+
"Harness.lawspec": "harness learn.threshold.testing for learn.threshold is\n strategy numbers :: (n :: Int32 where n >= 0 and n <= 200) is any end strategy\n for law \"|the answer agrees with being below eighty|\n use numbers for n\n end for law\nend harness\n"
|
|
1656
|
+
}
|
|
1657
|
+
},
|
|
1658
|
+
"sources": {
|
|
1659
|
+
"fsharp": {
|
|
1660
|
+
"Tests.lawspec": "exercises/threshold/solution/Tests.lawspec",
|
|
1661
|
+
"Harness.lawspec": "exercises/threshold/solution/Harness.lawspec",
|
|
1662
|
+
"Solution.fs": "exercises/threshold/01/fsharp/Solution.fs"
|
|
1663
|
+
},
|
|
1664
|
+
"typescript": {
|
|
1665
|
+
"Tests.lawspec": "exercises/threshold/solution/Tests.lawspec",
|
|
1666
|
+
"Harness.lawspec": "exercises/threshold/solution/Harness.lawspec",
|
|
1667
|
+
"Solution.ts": "exercises/threshold/01/typescript/Solution.ts"
|
|
1668
|
+
},
|
|
1669
|
+
"javascript": {
|
|
1670
|
+
"Tests.lawspec": "exercises/threshold/solution/Tests.lawspec",
|
|
1671
|
+
"Harness.lawspec": "exercises/threshold/solution/Harness.lawspec",
|
|
1672
|
+
"Solution.js": "exercises/threshold/01/javascript/Solution.js"
|
|
1673
|
+
}
|
|
1674
|
+
},
|
|
1675
|
+
"previousProjects": {
|
|
1676
|
+
"fsharp": {
|
|
1677
|
+
"Solution.fs": "module Solution\n\nlet isSmallerThan80 (n: int) : bool = n < 80\n",
|
|
1678
|
+
"Tests.lawspec": "-- ref:DEC-learn-tests-in-lawspec\nunit learn.threshold\nisSmallerThan80 :: Int32 -> Bool\n\nlaw seventyFive is\n definition:\n isSmallerThan80 75 = true\n end definition\nend law\n\nlaw lastBelow is\n definition:\n isSmallerThan80 79 = true\n end definition\nend law\n\nlaw boundaryIsNotBelow is\n definition:\n isSmallerThan80 80 = false\n end definition\nend law\n\nlaw classifiesTheBoundary is\n definition:\n for all (n :: Int32 where n >= 0 and n <= 200) => isSmallerThan80 n = (n <\n 80) end for all\n end definition\nend law\n\nend unit\n",
|
|
1679
|
+
"Harness.lawspec": "harness learn.threshold.testing for learn.threshold is\n strategy numbers :: (n :: Int32 where n >= 0 and n <= 200) is any end strategy\n for law classifiesTheBoundary\n use numbers for n\n end for law\nend harness\n"
|
|
1680
|
+
},
|
|
1681
|
+
"typescript": {
|
|
1682
|
+
"Solution.ts": "export function isSmallerThan80(n: number): boolean\n{\n return n < 80;\n}\n",
|
|
1683
|
+
"Tests.lawspec": "-- ref:DEC-learn-tests-in-lawspec\nunit learn.threshold\nisSmallerThan80 :: Int32 -> Bool\n\nlaw seventyFive is\n definition:\n isSmallerThan80 75 = true\n end definition\nend law\n\nlaw lastBelow is\n definition:\n isSmallerThan80 79 = true\n end definition\nend law\n\nlaw boundaryIsNotBelow is\n definition:\n isSmallerThan80 80 = false\n end definition\nend law\n\nlaw classifiesTheBoundary is\n definition:\n for all (n :: Int32 where n >= 0 and n <= 200) => isSmallerThan80 n = (n <\n 80) end for all\n end definition\nend law\n\nend unit\n",
|
|
1684
|
+
"Harness.lawspec": "harness learn.threshold.testing for learn.threshold is\n strategy numbers :: (n :: Int32 where n >= 0 and n <= 200) is any end strategy\n for law classifiesTheBoundary\n use numbers for n\n end for law\nend harness\n"
|
|
1685
|
+
},
|
|
1686
|
+
"javascript": {
|
|
1687
|
+
"Solution.js": "export function isSmallerThan80(n)\n{\n return n < 80;\n}\n",
|
|
1688
|
+
"Tests.lawspec": "-- ref:DEC-learn-tests-in-lawspec\nunit learn.threshold\nisSmallerThan80 :: Int32 -> Bool\n\nlaw seventyFive is\n definition:\n isSmallerThan80 75 = true\n end definition\nend law\n\nlaw lastBelow is\n definition:\n isSmallerThan80 79 = true\n end definition\nend law\n\nlaw boundaryIsNotBelow is\n definition:\n isSmallerThan80 80 = false\n end definition\nend law\n\nlaw classifiesTheBoundary is\n definition:\n for all (n :: Int32 where n >= 0 and n <= 200) => isSmallerThan80 n = (n <\n 80) end for all\n end definition\nend law\n\nend unit\n",
|
|
1689
|
+
"Harness.lawspec": "harness learn.threshold.testing for learn.threshold is\n strategy numbers :: (n :: Int32 where n >= 0 and n <= 200) is any end strategy\n for law classifiesTheBoundary\n use numbers for n\n end for law\nend harness\n"
|
|
1690
|
+
}
|
|
1691
|
+
}
|
|
1692
|
+
}
|
|
1693
|
+
],
|
|
1694
|
+
"solutionProject": "exercises/threshold/solution",
|
|
1695
|
+
"coverage": {
|
|
1696
|
+
"browserExecution": [
|
|
1697
|
+
"fsharp",
|
|
1698
|
+
"typescript",
|
|
1699
|
+
"javascript"
|
|
1700
|
+
],
|
|
1701
|
+
"definitionChecking": true,
|
|
1702
|
+
"nativeExecution": "deferred",
|
|
1703
|
+
"apiCollectionCredit": "deferred: this story is not a complete public API collection"
|
|
1704
|
+
},
|
|
1705
|
+
"implementationSyntax": {
|
|
1706
|
+
"fsharp": "In F#, bool is the true/false type. The comparison n < 80 produces a Boolean directly, without an if expression around it.",
|
|
1707
|
+
"typescript": "In TypeScript, boolean is the true/false type. return n < 80 returns the result of the comparison.",
|
|
1708
|
+
"javascript": "In JavaScript, return n < 80 returns the true/false result of the comparison."
|
|
1709
|
+
},
|
|
1710
|
+
"naming": "Use English phrase names for readable claims and descriptive LawSpec helpers. Keep short code names such as add, sort, xs and numbers when they make calls and recipes easier to follow. A phrase starts with \"| and ends with |, without a closing quote. A law label identifies the claim; renaming it does not change what the definition checks. The compiler generates target-appropriate names.",
|
|
1711
|
+
"projects": {
|
|
1712
|
+
"fsharp": {
|
|
1713
|
+
"Solution.fs": "module Solution\n\nlet isSmallerThan80 (n: int) : bool = n < 80\n",
|
|
1714
|
+
"Tests.lawspec": "-- ref:DEC-learn-tests-in-lawspec\nunit learn.threshold\nisSmallerThan80 :: Int32 -> Bool\n\nlaw \"|seventy five is below eighty| is\n definition:\n isSmallerThan80 75 = true\n end definition\nend law\n\nlaw \"|every number from zero to two hundred is below eighty| is\n definition:\n for all (n :: Int32 where n >= 0 and n <= 200) =>\n isSmallerThan80 n = true\n end for all\n end definition\nend law\n\nend unit\n",
|
|
1715
|
+
"Harness.lawspec": "harness learn.threshold.testing for learn.threshold is\n strategy numbers :: (n :: Int32 where n >= 0 and n <= 79) is any end strategy\n for law \"|every number from zero to two hundred is below eighty|\n use numbers for n\n end for law\nend harness\n"
|
|
1716
|
+
},
|
|
1717
|
+
"typescript": {
|
|
1718
|
+
"Solution.ts": "export function isSmallerThan80(n: number): boolean\n{\n return n < 80;\n}\n",
|
|
1719
|
+
"Tests.lawspec": "-- ref:DEC-learn-tests-in-lawspec\nunit learn.threshold\nisSmallerThan80 :: Int32 -> Bool\n\nlaw \"|seventy five is below eighty| is\n definition:\n isSmallerThan80 75 = true\n end definition\nend law\n\nlaw \"|every number from zero to two hundred is below eighty| is\n definition:\n for all (n :: Int32 where n >= 0 and n <= 200) =>\n isSmallerThan80 n = true\n end for all\n end definition\nend law\n\nend unit\n",
|
|
1720
|
+
"Harness.lawspec": "harness learn.threshold.testing for learn.threshold is\n strategy numbers :: (n :: Int32 where n >= 0 and n <= 79) is any end strategy\n for law \"|every number from zero to two hundred is below eighty|\n use numbers for n\n end for law\nend harness\n"
|
|
1721
|
+
},
|
|
1722
|
+
"javascript": {
|
|
1723
|
+
"Solution.js": "export function isSmallerThan80(n)\n{\n return n < 80;\n}\n",
|
|
1724
|
+
"Tests.lawspec": "-- ref:DEC-learn-tests-in-lawspec\nunit learn.threshold\nisSmallerThan80 :: Int32 -> Bool\n\nlaw \"|seventy five is below eighty| is\n definition:\n isSmallerThan80 75 = true\n end definition\nend law\n\nlaw \"|every number from zero to two hundred is below eighty| is\n definition:\n for all (n :: Int32 where n >= 0 and n <= 200) =>\n isSmallerThan80 n = true\n end for all\n end definition\nend law\n\nend unit\n",
|
|
1725
|
+
"Harness.lawspec": "harness learn.threshold.testing for learn.threshold is\n strategy numbers :: (n :: Int32 where n >= 0 and n <= 79) is any end strategy\n for law \"|every number from zero to two hundred is below eighty|\n use numbers for n\n end for law\nend harness\n"
|
|
1726
|
+
}
|
|
1727
|
+
},
|
|
1728
|
+
"solutions": {
|
|
1729
|
+
"fsharp": {
|
|
1730
|
+
"Solution.fs": "module Solution\n\nlet isSmallerThan80 (n: int) : bool = n < 80\n",
|
|
1731
|
+
"Tests.lawspec": "-- ref:DEC-learn-tests-in-lawspec\nunit learn.threshold\nisSmallerThan80 :: Int32 -> Bool\n\nlaw \"|seventy five is below eighty| is\n definition:\n isSmallerThan80 75 = true\n end definition\nend law\n\nlaw \"|seventy nine is below eighty| is\n definition:\n isSmallerThan80 79 = true\n end definition\nend law\n\nlaw \"|eighty is not below eighty| is\n definition:\n isSmallerThan80 80 = false\n end definition\nend law\n\nlaw \"|the answer agrees with being below eighty| is\n definition:\n for all (n :: Int32 where n >= 0 and n <= 200) =>\n isSmallerThan80 n = (n < 80)\n end for all\n end definition\nend law\n\nend unit\n",
|
|
1732
|
+
"Harness.lawspec": "harness learn.threshold.testing for learn.threshold is\n strategy numbers :: (n :: Int32 where n >= 0 and n <= 200) is any end strategy\n for law \"|the answer agrees with being below eighty|\n use numbers for n\n end for law\nend harness\n"
|
|
1733
|
+
},
|
|
1734
|
+
"typescript": {
|
|
1735
|
+
"Solution.ts": "export function isSmallerThan80(n: number): boolean\n{\n return n < 80;\n}\n",
|
|
1736
|
+
"Tests.lawspec": "-- ref:DEC-learn-tests-in-lawspec\nunit learn.threshold\nisSmallerThan80 :: Int32 -> Bool\n\nlaw \"|seventy five is below eighty| is\n definition:\n isSmallerThan80 75 = true\n end definition\nend law\n\nlaw \"|seventy nine is below eighty| is\n definition:\n isSmallerThan80 79 = true\n end definition\nend law\n\nlaw \"|eighty is not below eighty| is\n definition:\n isSmallerThan80 80 = false\n end definition\nend law\n\nlaw \"|the answer agrees with being below eighty| is\n definition:\n for all (n :: Int32 where n >= 0 and n <= 200) =>\n isSmallerThan80 n = (n < 80)\n end for all\n end definition\nend law\n\nend unit\n",
|
|
1737
|
+
"Harness.lawspec": "harness learn.threshold.testing for learn.threshold is\n strategy numbers :: (n :: Int32 where n >= 0 and n <= 200) is any end strategy\n for law \"|the answer agrees with being below eighty|\n use numbers for n\n end for law\nend harness\n"
|
|
1738
|
+
},
|
|
1739
|
+
"javascript": {
|
|
1740
|
+
"Solution.js": "export function isSmallerThan80(n)\n{\n return n < 80;\n}\n",
|
|
1741
|
+
"Tests.lawspec": "-- ref:DEC-learn-tests-in-lawspec\nunit learn.threshold\nisSmallerThan80 :: Int32 -> Bool\n\nlaw \"|seventy five is below eighty| is\n definition:\n isSmallerThan80 75 = true\n end definition\nend law\n\nlaw \"|seventy nine is below eighty| is\n definition:\n isSmallerThan80 79 = true\n end definition\nend law\n\nlaw \"|eighty is not below eighty| is\n definition:\n isSmallerThan80 80 = false\n end definition\nend law\n\nlaw \"|the answer agrees with being below eighty| is\n definition:\n for all (n :: Int32 where n >= 0 and n <= 200) =>\n isSmallerThan80 n = (n < 80)\n end for all\n end definition\nend law\n\nend unit\n",
|
|
1742
|
+
"Harness.lawspec": "harness learn.threshold.testing for learn.threshold is\n strategy numbers :: (n :: Int32 where n >= 0 and n <= 200) is any end strategy\n for law \"|the answer agrees with being below eighty|\n use numbers for n\n end for law\nend harness\n"
|
|
1743
|
+
}
|
|
1744
|
+
},
|
|
1745
|
+
"solutionSources": {
|
|
1746
|
+
"fsharp": {
|
|
1747
|
+
"Tests.lawspec": "exercises/threshold/solution/Tests.lawspec",
|
|
1748
|
+
"Harness.lawspec": "exercises/threshold/solution/Harness.lawspec",
|
|
1749
|
+
"Solution.fs": "exercises/threshold/01/fsharp/Solution.fs"
|
|
1750
|
+
},
|
|
1751
|
+
"typescript": {
|
|
1752
|
+
"Tests.lawspec": "exercises/threshold/solution/Tests.lawspec",
|
|
1753
|
+
"Harness.lawspec": "exercises/threshold/solution/Harness.lawspec",
|
|
1754
|
+
"Solution.ts": "exercises/threshold/01/typescript/Solution.ts"
|
|
1755
|
+
},
|
|
1756
|
+
"javascript": {
|
|
1757
|
+
"Tests.lawspec": "exercises/threshold/solution/Tests.lawspec",
|
|
1758
|
+
"Harness.lawspec": "exercises/threshold/solution/Harness.lawspec",
|
|
1759
|
+
"Solution.js": "exercises/threshold/01/javascript/Solution.js"
|
|
1760
|
+
}
|
|
1761
|
+
}
|
|
1762
|
+
},
|
|
1763
|
+
{
|
|
1764
|
+
"id": "examples",
|
|
1765
|
+
"title": "Practice: estimate seats for any hall size",
|
|
1766
|
+
"section": "Apply the ideas",
|
|
1767
|
+
"vision": "Use the calculator lesson’s method to repair a hall seating estimate.",
|
|
1768
|
+
"slogan": "Four seats for every row.",
|
|
1769
|
+
"symbol": "1 row → 4 seats; 3 rows → 12 seats",
|
|
1770
|
+
"explanation": "Laws and generation strategies are authored in LawSpec. Only the implementation changes language.",
|
|
1771
|
+
"news": "A rule about every allowed row count can reject a lookup table of familiar answers.",
|
|
1772
|
+
"contributions": "A seating function, the failing third-row example, and the LawSpec relationship seats rows = rows * 4 for rows 0–40. The repaired function must pass the unchanged named and generated checks.",
|
|
1773
|
+
"star": {
|
|
1774
|
+
"salient": "A rule about every allowed row count can reject a lookup table of familiar answers.",
|
|
1775
|
+
"slogan": "Four seats for every row.",
|
|
1776
|
+
"symbol": "1 row → 4 seats; 3 rows → 12 seats",
|
|
1777
|
+
"surprise": "The estimator passes its familiar halls but reports zero seats for a three-row hall.",
|
|
1778
|
+
"story": "An organizer’s two familiar halls pass. A new hall exposes the lookup table; the row-to-seat rule then guides a general repair."
|
|
1779
|
+
},
|
|
1780
|
+
"attribution": [
|
|
1781
|
+
{
|
|
1782
|
+
"title": "Scott Wlaschin — The Enterprise Developer from Hell",
|
|
1783
|
+
"url": "https://fsharpforfunandprofit.com/posts/property-based-testing/",
|
|
1784
|
+
"use": "Original application exercise following the licensed addition examples."
|
|
1785
|
+
}
|
|
1786
|
+
],
|
|
1787
|
+
"hints": [
|
|
1788
|
+
"For three rows, what branch runs and what total is needed?",
|
|
1789
|
+
"Use the number of seats in one row to express the total for any allowed row count.",
|
|
1790
|
+
"Keep the 0–40 domain and the tests while repairing Solution. Load solution gives the complete estimator."
|
|
1791
|
+
],
|
|
1792
|
+
"stages": [
|
|
1793
|
+
{
|
|
1794
|
+
"id": "familiar",
|
|
1795
|
+
"title": "The organizer has two familiar halls",
|
|
1796
|
+
"story": [
|
|
1797
|
+
"An event organizer needs a seating estimate. Each row has four seats, and this exercise allows 0 through 40 rows. The function takes a row count and should return the total number of seats. You will turn familiar examples into a rule that handles unfamiliar hall sizes too.",
|
|
1798
|
+
"Solution recognizes only one-row and two-row halls, returning 0 for any other size. Laws currently asks only for those familiar halls.",
|
|
1799
|
+
"Run the examples, then predict what a three-row request would receive. You are applying the calculator lesson: distinguish remembering two answers from implementing the rule.",
|
|
1800
|
+
"The English claim names describe the hall requests. seats stays a short function name because the input and output already tell us how to read a call."
|
|
1801
|
+
],
|
|
1802
|
+
"focus": "Solution",
|
|
1803
|
+
"project": "exercises/examples/01",
|
|
1804
|
+
"run": {
|
|
1805
|
+
"mode": "examples",
|
|
1806
|
+
"expect": "passed",
|
|
1807
|
+
"seed": 424242
|
|
1808
|
+
},
|
|
1809
|
+
"action": "Run the familiar examples and predict the result for three rows by tracing Solution.",
|
|
1810
|
+
"reason": "The useful requirement is a relationship between rows and seats, not a list of familiar hall sizes.",
|
|
1811
|
+
"expect": "The supplied code compiles and the selected checks pass. Read which checks actually ran before interpreting this result.",
|
|
1812
|
+
"recovery": "Reset this step restores its supplied files and seed. After an edit, use the actual result to judge your version; the story’s prediction describes the supplied files.",
|
|
1813
|
+
"editor": "Tests",
|
|
1814
|
+
"syntax": "seats takes one integer input and returns an integer. A concrete law calls it with a row count and compares the result with an expected total.",
|
|
1815
|
+
"harnessNotes": [
|
|
1816
|
+
"This harness has no strategy yet: this step runs the concrete claims in Laws on their written inputs. An empty harness is not an empty test suite. Later, a quantified law will need generated inputs."
|
|
1817
|
+
],
|
|
1818
|
+
"symbol": "1 row → 4 seats; 3 rows → 12 seats",
|
|
1819
|
+
"projects": {
|
|
1820
|
+
"fsharp": {
|
|
1821
|
+
"Solution.fs": "module Solution\n\n// One row has four seats. This implementation knows only our examples.\nlet seats (rows: int) : int =\n if rows = 1 then 4\n elif rows = 2 then 8\n else 0\n",
|
|
1822
|
+
"Tests.lawspec": "-- ref:DEC-learn-tests-in-lawspec\nunit learn.seats\nseats :: Int32 -> Int32\n\nlaw \"|one row has four seats| is\n definition:\n seats 1 = 4\n end definition\nend law\n\nlaw \"|two rows have eight seats| is\n definition:\n seats 2 = 8\n end definition\nend law\n\nend unit\n",
|
|
1823
|
+
"Harness.lawspec": "harness learn.seats.testing for learn.seats is\n -- This step checks concrete inputs; no generator is selected.\nend harness\n"
|
|
1824
|
+
},
|
|
1825
|
+
"typescript": {
|
|
1826
|
+
"Solution.ts": "export function seats(rows: number): number\n{\n return rows === 1 ? 4 : rows === 2 ? 8 : 0;\n}\n",
|
|
1827
|
+
"Tests.lawspec": "-- ref:DEC-learn-tests-in-lawspec\nunit learn.seats\nseats :: Int32 -> Int32\n\nlaw \"|one row has four seats| is\n definition:\n seats 1 = 4\n end definition\nend law\n\nlaw \"|two rows have eight seats| is\n definition:\n seats 2 = 8\n end definition\nend law\n\nend unit\n",
|
|
1828
|
+
"Harness.lawspec": "harness learn.seats.testing for learn.seats is\n -- This step checks concrete inputs; no generator is selected.\nend harness\n"
|
|
1829
|
+
},
|
|
1830
|
+
"javascript": {
|
|
1831
|
+
"Solution.js": "export function seats(rows)\n{\n return rows === 1 ? 4 : rows === 2 ? 8 : 0;\n}\n",
|
|
1832
|
+
"Tests.lawspec": "-- ref:DEC-learn-tests-in-lawspec\nunit learn.seats\nseats :: Int32 -> Int32\n\nlaw \"|one row has four seats| is\n definition:\n seats 1 = 4\n end definition\nend law\n\nlaw \"|two rows have eight seats| is\n definition:\n seats 2 = 8\n end definition\nend law\n\nend unit\n",
|
|
1833
|
+
"Harness.lawspec": "harness learn.seats.testing for learn.seats is\n -- This step checks concrete inputs; no generator is selected.\nend harness\n"
|
|
1834
|
+
}
|
|
1835
|
+
},
|
|
1836
|
+
"sources": {
|
|
1837
|
+
"fsharp": {
|
|
1838
|
+
"Tests.lawspec": "exercises/examples/01/Tests.lawspec",
|
|
1839
|
+
"Harness.lawspec": "exercises/examples/01/Harness.lawspec",
|
|
1840
|
+
"Solution.fs": "exercises/examples/01/fsharp/Solution.fs"
|
|
1841
|
+
},
|
|
1842
|
+
"typescript": {
|
|
1843
|
+
"Tests.lawspec": "exercises/examples/01/Tests.lawspec",
|
|
1844
|
+
"Harness.lawspec": "exercises/examples/01/Harness.lawspec",
|
|
1845
|
+
"Solution.ts": "exercises/examples/01/typescript/Solution.ts"
|
|
1846
|
+
},
|
|
1847
|
+
"javascript": {
|
|
1848
|
+
"Tests.lawspec": "exercises/examples/01/Tests.lawspec",
|
|
1849
|
+
"Harness.lawspec": "exercises/examples/01/Harness.lawspec",
|
|
1850
|
+
"Solution.js": "exercises/examples/01/javascript/Solution.js"
|
|
1851
|
+
}
|
|
1852
|
+
},
|
|
1853
|
+
"previousProjects": {
|
|
1854
|
+
"fsharp": {
|
|
1855
|
+
"Solution.fs": "module Solution\n\n// One row has four seats. This implementation knows only our examples.\nlet seats (rows: int) : int =\n if rows = 1 then 4\n elif rows = 2 then 8\n else 0\n",
|
|
1856
|
+
"Tests.lawspec": "-- ref:DEC-learn-tests-in-lawspec\nunit learn.seats\nseats :: Int32 -> Int32\n\nlaw oneRow is\n definition:\n seats 1 = 4\n end definition\nend law\n\nlaw twoRows is\n definition:\n seats 2 = 8\n end definition\nend law\n\nend unit\n",
|
|
1857
|
+
"Harness.lawspec": "harness learn.seats.testing for learn.seats is\n -- This step checks concrete inputs; no generator is selected.\nend harness\n"
|
|
1858
|
+
},
|
|
1859
|
+
"typescript": {
|
|
1860
|
+
"Solution.ts": "export function seats(rows: number): number\n{\n return rows === 1 ? 4 : rows === 2 ? 8 : 0;\n}\n",
|
|
1861
|
+
"Tests.lawspec": "-- ref:DEC-learn-tests-in-lawspec\nunit learn.seats\nseats :: Int32 -> Int32\n\nlaw oneRow is\n definition:\n seats 1 = 4\n end definition\nend law\n\nlaw twoRows is\n definition:\n seats 2 = 8\n end definition\nend law\n\nend unit\n",
|
|
1862
|
+
"Harness.lawspec": "harness learn.seats.testing for learn.seats is\n -- This step checks concrete inputs; no generator is selected.\nend harness\n"
|
|
1863
|
+
},
|
|
1864
|
+
"javascript": {
|
|
1865
|
+
"Solution.js": "export function seats(rows)\n{\n return rows === 1 ? 4 : rows === 2 ? 8 : 0;\n}\n",
|
|
1866
|
+
"Tests.lawspec": "-- ref:DEC-learn-tests-in-lawspec\nunit learn.seats\nseats :: Int32 -> Int32\n\nlaw oneRow is\n definition:\n seats 1 = 4\n end definition\nend law\n\nlaw twoRows is\n definition:\n seats 2 = 8\n end definition\nend law\n\nend unit\n",
|
|
1867
|
+
"Harness.lawspec": "harness learn.seats.testing for learn.seats is\n -- This step checks concrete inputs; no generator is selected.\nend harness\n"
|
|
1868
|
+
}
|
|
1869
|
+
}
|
|
1870
|
+
},
|
|
1871
|
+
{
|
|
1872
|
+
"id": "third-row",
|
|
1873
|
+
"title": "A three-row hall exposes the shortcut",
|
|
1874
|
+
"story": [
|
|
1875
|
+
"The organizer asks for three rows. Laws adds “three rows have twelve seats”, expecting 12 seats. Solution is unchanged.",
|
|
1876
|
+
"Use Run checks with Examples + boundaries. The original answers still pass, but “three rows have twelve seats” fails because the remaining branch returns 0. This is a concrete demonstration of the missing behavior."
|
|
1877
|
+
],
|
|
1878
|
+
"focus": "Tests",
|
|
1879
|
+
"project": "exercises/examples/02",
|
|
1880
|
+
"run": {
|
|
1881
|
+
"mode": "examples",
|
|
1882
|
+
"expect": "failed",
|
|
1883
|
+
"failedTests": [
|
|
1884
|
+
"learn.seats::|three rows have twelve seats| boundary 1"
|
|
1885
|
+
],
|
|
1886
|
+
"seed": 424242
|
|
1887
|
+
},
|
|
1888
|
+
"action": "Use Run checks with Examples + boundaries, locate “three rows have twelve seats” and explain why the existing branches miss this hall.",
|
|
1889
|
+
"reason": "A new request reveals the limits of the passing examples.",
|
|
1890
|
+
"expect": "The supplied code compiles, then the selected checks fail. A compiler error is a different problem; inspect diagnostics if execution did not start.",
|
|
1891
|
+
"recovery": "Reset this step restores its supplied files and seed. After an edit, use the actual result to judge your version; the story’s prediction describes the supplied files.",
|
|
1892
|
+
"editor": "Solution",
|
|
1893
|
+
"syntax": "“three rows have twelve seats” is a named concrete law. Its result reports this particular request independently of the earlier ones.",
|
|
1894
|
+
"harnessNotes": [
|
|
1895
|
+
"This harness has no strategy yet: this step runs the concrete claims in Laws on their written inputs. An empty harness is not an empty test suite. Later, a quantified law will need generated inputs."
|
|
1896
|
+
],
|
|
1897
|
+
"projects": {
|
|
1898
|
+
"fsharp": {
|
|
1899
|
+
"Solution.fs": "module Solution\n\n// One row has four seats. This implementation knows only our examples.\nlet seats (rows: int) : int =\n if rows = 1 then 4\n elif rows = 2 then 8\n else 0\n",
|
|
1900
|
+
"Tests.lawspec": "-- ref:DEC-learn-tests-in-lawspec\nunit learn.seats\nseats :: Int32 -> Int32\n\nlaw \"|one row has four seats| is\n definition:\n seats 1 = 4\n end definition\nend law\n\nlaw \"|two rows have eight seats| is\n definition:\n seats 2 = 8\n end definition\nend law\n\nlaw \"|three rows have twelve seats| is\n definition:\n seats 3 = 12\n end definition\nend law\n\nend unit\n",
|
|
1901
|
+
"Harness.lawspec": "harness learn.seats.testing for learn.seats is\n -- This step checks concrete inputs; no generator is selected.\nend harness\n"
|
|
1902
|
+
},
|
|
1903
|
+
"typescript": {
|
|
1904
|
+
"Solution.ts": "export function seats(rows: number): number\n{\n return rows === 1 ? 4 : rows === 2 ? 8 : 0;\n}\n",
|
|
1905
|
+
"Tests.lawspec": "-- ref:DEC-learn-tests-in-lawspec\nunit learn.seats\nseats :: Int32 -> Int32\n\nlaw \"|one row has four seats| is\n definition:\n seats 1 = 4\n end definition\nend law\n\nlaw \"|two rows have eight seats| is\n definition:\n seats 2 = 8\n end definition\nend law\n\nlaw \"|three rows have twelve seats| is\n definition:\n seats 3 = 12\n end definition\nend law\n\nend unit\n",
|
|
1906
|
+
"Harness.lawspec": "harness learn.seats.testing for learn.seats is\n -- This step checks concrete inputs; no generator is selected.\nend harness\n"
|
|
1907
|
+
},
|
|
1908
|
+
"javascript": {
|
|
1909
|
+
"Solution.js": "export function seats(rows)\n{\n return rows === 1 ? 4 : rows === 2 ? 8 : 0;\n}\n",
|
|
1910
|
+
"Tests.lawspec": "-- ref:DEC-learn-tests-in-lawspec\nunit learn.seats\nseats :: Int32 -> Int32\n\nlaw \"|one row has four seats| is\n definition:\n seats 1 = 4\n end definition\nend law\n\nlaw \"|two rows have eight seats| is\n definition:\n seats 2 = 8\n end definition\nend law\n\nlaw \"|three rows have twelve seats| is\n definition:\n seats 3 = 12\n end definition\nend law\n\nend unit\n",
|
|
1911
|
+
"Harness.lawspec": "harness learn.seats.testing for learn.seats is\n -- This step checks concrete inputs; no generator is selected.\nend harness\n"
|
|
1912
|
+
}
|
|
1913
|
+
},
|
|
1914
|
+
"sources": {
|
|
1915
|
+
"fsharp": {
|
|
1916
|
+
"Tests.lawspec": "exercises/examples/02/Tests.lawspec",
|
|
1917
|
+
"Harness.lawspec": "exercises/examples/02/Harness.lawspec",
|
|
1918
|
+
"Solution.fs": "exercises/examples/01/fsharp/Solution.fs"
|
|
1919
|
+
},
|
|
1920
|
+
"typescript": {
|
|
1921
|
+
"Tests.lawspec": "exercises/examples/02/Tests.lawspec",
|
|
1922
|
+
"Harness.lawspec": "exercises/examples/02/Harness.lawspec",
|
|
1923
|
+
"Solution.ts": "exercises/examples/01/typescript/Solution.ts"
|
|
1924
|
+
},
|
|
1925
|
+
"javascript": {
|
|
1926
|
+
"Tests.lawspec": "exercises/examples/02/Tests.lawspec",
|
|
1927
|
+
"Harness.lawspec": "exercises/examples/02/Harness.lawspec",
|
|
1928
|
+
"Solution.js": "exercises/examples/01/javascript/Solution.js"
|
|
1929
|
+
}
|
|
1930
|
+
},
|
|
1931
|
+
"previousProjects": {
|
|
1932
|
+
"fsharp": {
|
|
1933
|
+
"Solution.fs": "module Solution\n\n// One row has four seats. This implementation knows only our examples.\nlet seats (rows: int) : int =\n if rows = 1 then 4\n elif rows = 2 then 8\n else 0\n",
|
|
1934
|
+
"Tests.lawspec": "-- ref:DEC-learn-tests-in-lawspec\nunit learn.seats\nseats :: Int32 -> Int32\n\nlaw oneRow is\n definition:\n seats 1 = 4\n end definition\nend law\n\nlaw twoRows is\n definition:\n seats 2 = 8\n end definition\nend law\n\nlaw thirdRow is\n definition:\n seats 3 = 12\n end definition\nend law\n\nend unit\n",
|
|
1935
|
+
"Harness.lawspec": "harness learn.seats.testing for learn.seats is\n -- This step checks concrete inputs; no generator is selected.\nend harness\n"
|
|
1936
|
+
},
|
|
1937
|
+
"typescript": {
|
|
1938
|
+
"Solution.ts": "export function seats(rows: number): number\n{\n return rows === 1 ? 4 : rows === 2 ? 8 : 0;\n}\n",
|
|
1939
|
+
"Tests.lawspec": "-- ref:DEC-learn-tests-in-lawspec\nunit learn.seats\nseats :: Int32 -> Int32\n\nlaw oneRow is\n definition:\n seats 1 = 4\n end definition\nend law\n\nlaw twoRows is\n definition:\n seats 2 = 8\n end definition\nend law\n\nlaw thirdRow is\n definition:\n seats 3 = 12\n end definition\nend law\n\nend unit\n",
|
|
1940
|
+
"Harness.lawspec": "harness learn.seats.testing for learn.seats is\n -- This step checks concrete inputs; no generator is selected.\nend harness\n"
|
|
1941
|
+
},
|
|
1942
|
+
"javascript": {
|
|
1943
|
+
"Solution.js": "export function seats(rows)\n{\n return rows === 1 ? 4 : rows === 2 ? 8 : 0;\n}\n",
|
|
1944
|
+
"Tests.lawspec": "-- ref:DEC-learn-tests-in-lawspec\nunit learn.seats\nseats :: Int32 -> Int32\n\nlaw oneRow is\n definition:\n seats 1 = 4\n end definition\nend law\n\nlaw twoRows is\n definition:\n seats 2 = 8\n end definition\nend law\n\nlaw thirdRow is\n definition:\n seats 3 = 12\n end definition\nend law\n\nend unit\n",
|
|
1945
|
+
"Harness.lawspec": "harness learn.seats.testing for learn.seats is\n -- This step checks concrete inputs; no generator is selected.\nend harness\n"
|
|
1946
|
+
}
|
|
1947
|
+
}
|
|
1948
|
+
},
|
|
1949
|
+
{
|
|
1950
|
+
"id": "repair",
|
|
1951
|
+
"title": "Implement the row-to-seat rule",
|
|
1952
|
+
"story": [
|
|
1953
|
+
"“every row contributes four seats” in Laws states the relationship for row counts 0 through 40: the answer is four times the count. Harness supplies rows from that domain. The lookup-table implementation remains so you can observe its failure first.",
|
|
1954
|
+
"Use Run checks with All checks, then repair Solution using the relationship. Rerun without replacing the rule with a list of special cases.",
|
|
1955
|
+
"Your own checks should include an empty hall and the largest allowed hall. Predict their totals, write named laws for them and run again. You will have an estimator tested on familiar examples, boundary examples and sampled row counts."
|
|
1956
|
+
],
|
|
1957
|
+
"focus": "Tests",
|
|
1958
|
+
"project": "exercises/examples/03",
|
|
1959
|
+
"run": {
|
|
1960
|
+
"mode": "all",
|
|
1961
|
+
"expect": "failed",
|
|
1962
|
+
"sampled": "failed",
|
|
1963
|
+
"seed": 424242
|
|
1964
|
+
},
|
|
1965
|
+
"action": "Observe the shortcut fail, implement the general estimate, and add named checks for 0 and 40 rows.",
|
|
1966
|
+
"reason": "Four seats for every row. One relationship covers the hall sizes that the lookup table forgot.",
|
|
1967
|
+
"expect": "The supplied code compiles, then the selected checks fail. A compiler error is a different problem; inspect diagnostics if execution did not start.",
|
|
1968
|
+
"recovery": "Reset this step restores its supplied files and seed. After an edit, use the actual result to judge your version; the story’s prediction describes the supplied files.",
|
|
1969
|
+
"challenge": true,
|
|
1970
|
+
"editor": "Solution",
|
|
1971
|
+
"syntax": "for all introduces rows within the stated bounds. The law computes an expected total from rows and compares it with seats rows.",
|
|
1972
|
+
"harnessNotes": [
|
|
1973
|
+
"numbers draws row counts from 0 through 40, including the endpoints. The binding for “every row contributes four seats” selects the requirement in Laws; use numbers for rows supplies its rows input. The law calls the actual seats function and checks its output."
|
|
1974
|
+
],
|
|
1975
|
+
"projects": {
|
|
1976
|
+
"fsharp": {
|
|
1977
|
+
"Solution.fs": "module Solution\n\n// One row has four seats. This implementation knows only our examples.\nlet seats (rows: int) : int =\n if rows = 1 then 4\n elif rows = 2 then 8\n else 0\n",
|
|
1978
|
+
"Tests.lawspec": "-- ref:DEC-learn-tests-in-lawspec\nunit learn.seats\nseats :: Int32 -> Int32\n\nlaw \"|one row has four seats| is\n definition:\n seats 1 = 4\n end definition\nend law\n\nlaw \"|two rows have eight seats| is\n definition:\n seats 2 = 8\n end definition\nend law\n\nlaw \"|three rows have twelve seats| is\n definition:\n seats 3 = 12\n end definition\nend law\n\nlaw \"|every row contributes four seats| is\n definition:\n for all (rows :: Int32 where rows >= 0 and rows <= 40) =>\n seats rows = rows * 4\n end for all\n end definition\nend law\n\nend unit\n",
|
|
1979
|
+
"Harness.lawspec": "harness learn.seats.testing for learn.seats is\n strategy numbers :: (n :: Int32 where n >= 0 and n <= 40) is any end strategy\n for law \"|every row contributes four seats|\n use numbers for rows\n end for law\nend harness\n"
|
|
1980
|
+
},
|
|
1981
|
+
"typescript": {
|
|
1982
|
+
"Solution.ts": "export function seats(rows: number): number\n{\n return rows === 1 ? 4 : rows === 2 ? 8 : 0;\n}\n",
|
|
1983
|
+
"Tests.lawspec": "-- ref:DEC-learn-tests-in-lawspec\nunit learn.seats\nseats :: Int32 -> Int32\n\nlaw \"|one row has four seats| is\n definition:\n seats 1 = 4\n end definition\nend law\n\nlaw \"|two rows have eight seats| is\n definition:\n seats 2 = 8\n end definition\nend law\n\nlaw \"|three rows have twelve seats| is\n definition:\n seats 3 = 12\n end definition\nend law\n\nlaw \"|every row contributes four seats| is\n definition:\n for all (rows :: Int32 where rows >= 0 and rows <= 40) =>\n seats rows = rows * 4\n end for all\n end definition\nend law\n\nend unit\n",
|
|
1984
|
+
"Harness.lawspec": "harness learn.seats.testing for learn.seats is\n strategy numbers :: (n :: Int32 where n >= 0 and n <= 40) is any end strategy\n for law \"|every row contributes four seats|\n use numbers for rows\n end for law\nend harness\n"
|
|
1985
|
+
},
|
|
1986
|
+
"javascript": {
|
|
1987
|
+
"Solution.js": "export function seats(rows)\n{\n return rows === 1 ? 4 : rows === 2 ? 8 : 0;\n}\n",
|
|
1988
|
+
"Tests.lawspec": "-- ref:DEC-learn-tests-in-lawspec\nunit learn.seats\nseats :: Int32 -> Int32\n\nlaw \"|one row has four seats| is\n definition:\n seats 1 = 4\n end definition\nend law\n\nlaw \"|two rows have eight seats| is\n definition:\n seats 2 = 8\n end definition\nend law\n\nlaw \"|three rows have twelve seats| is\n definition:\n seats 3 = 12\n end definition\nend law\n\nlaw \"|every row contributes four seats| is\n definition:\n for all (rows :: Int32 where rows >= 0 and rows <= 40) =>\n seats rows = rows * 4\n end for all\n end definition\nend law\n\nend unit\n",
|
|
1989
|
+
"Harness.lawspec": "harness learn.seats.testing for learn.seats is\n strategy numbers :: (n :: Int32 where n >= 0 and n <= 40) is any end strategy\n for law \"|every row contributes four seats|\n use numbers for rows\n end for law\nend harness\n"
|
|
1990
|
+
}
|
|
1991
|
+
},
|
|
1992
|
+
"sources": {
|
|
1993
|
+
"fsharp": {
|
|
1994
|
+
"Tests.lawspec": "exercises/examples/03/Tests.lawspec",
|
|
1995
|
+
"Harness.lawspec": "exercises/examples/03/Harness.lawspec",
|
|
1996
|
+
"Solution.fs": "exercises/examples/01/fsharp/Solution.fs"
|
|
1997
|
+
},
|
|
1998
|
+
"typescript": {
|
|
1999
|
+
"Tests.lawspec": "exercises/examples/03/Tests.lawspec",
|
|
2000
|
+
"Harness.lawspec": "exercises/examples/03/Harness.lawspec",
|
|
2001
|
+
"Solution.ts": "exercises/examples/01/typescript/Solution.ts"
|
|
2002
|
+
},
|
|
2003
|
+
"javascript": {
|
|
2004
|
+
"Tests.lawspec": "exercises/examples/03/Tests.lawspec",
|
|
2005
|
+
"Harness.lawspec": "exercises/examples/03/Harness.lawspec",
|
|
2006
|
+
"Solution.js": "exercises/examples/01/javascript/Solution.js"
|
|
2007
|
+
}
|
|
2008
|
+
},
|
|
2009
|
+
"previousProjects": {
|
|
2010
|
+
"fsharp": {
|
|
2011
|
+
"Solution.fs": "module Solution\n\n// One row has four seats. This implementation knows only our examples.\nlet seats (rows: int) : int =\n if rows = 1 then 4\n elif rows = 2 then 8\n else 0\n",
|
|
2012
|
+
"Tests.lawspec": "-- ref:DEC-learn-tests-in-lawspec\nunit learn.seats\nseats :: Int32 -> Int32\n\nlaw oneRow is\n definition:\n seats 1 = 4\n end definition\nend law\n\nlaw twoRows is\n definition:\n seats 2 = 8\n end definition\nend law\n\nlaw thirdRow is\n definition:\n seats 3 = 12\n end definition\nend law\n\nlaw seatsRule is\n definition:\n for all (rows :: Int32 where rows >= 0 and rows <= 40) => seats rows = rows\n * 4 end for all\n end definition\nend law\n\nend unit\n",
|
|
2013
|
+
"Harness.lawspec": "harness learn.seats.testing for learn.seats is\n strategy numbers :: (n :: Int32 where n >= 0 and n <= 40) is any end strategy\n for law seatsRule\n use numbers for rows\n end for law\nend harness\n"
|
|
2014
|
+
},
|
|
2015
|
+
"typescript": {
|
|
2016
|
+
"Solution.ts": "export function seats(rows: number): number\n{\n return rows === 1 ? 4 : rows === 2 ? 8 : 0;\n}\n",
|
|
2017
|
+
"Tests.lawspec": "-- ref:DEC-learn-tests-in-lawspec\nunit learn.seats\nseats :: Int32 -> Int32\n\nlaw oneRow is\n definition:\n seats 1 = 4\n end definition\nend law\n\nlaw twoRows is\n definition:\n seats 2 = 8\n end definition\nend law\n\nlaw thirdRow is\n definition:\n seats 3 = 12\n end definition\nend law\n\nlaw seatsRule is\n definition:\n for all (rows :: Int32 where rows >= 0 and rows <= 40) => seats rows = rows\n * 4 end for all\n end definition\nend law\n\nend unit\n",
|
|
2018
|
+
"Harness.lawspec": "harness learn.seats.testing for learn.seats is\n strategy numbers :: (n :: Int32 where n >= 0 and n <= 40) is any end strategy\n for law seatsRule\n use numbers for rows\n end for law\nend harness\n"
|
|
2019
|
+
},
|
|
2020
|
+
"javascript": {
|
|
2021
|
+
"Solution.js": "export function seats(rows)\n{\n return rows === 1 ? 4 : rows === 2 ? 8 : 0;\n}\n",
|
|
2022
|
+
"Tests.lawspec": "-- ref:DEC-learn-tests-in-lawspec\nunit learn.seats\nseats :: Int32 -> Int32\n\nlaw oneRow is\n definition:\n seats 1 = 4\n end definition\nend law\n\nlaw twoRows is\n definition:\n seats 2 = 8\n end definition\nend law\n\nlaw thirdRow is\n definition:\n seats 3 = 12\n end definition\nend law\n\nlaw seatsRule is\n definition:\n for all (rows :: Int32 where rows >= 0 and rows <= 40) => seats rows = rows\n * 4 end for all\n end definition\nend law\n\nend unit\n",
|
|
2023
|
+
"Harness.lawspec": "harness learn.seats.testing for learn.seats is\n strategy numbers :: (n :: Int32 where n >= 0 and n <= 40) is any end strategy\n for law seatsRule\n use numbers for rows\n end for law\nend harness\n"
|
|
2024
|
+
}
|
|
2025
|
+
}
|
|
2026
|
+
}
|
|
2027
|
+
],
|
|
2028
|
+
"solutionProject": "exercises/examples/solution",
|
|
2029
|
+
"coverage": {
|
|
2030
|
+
"browserExecution": [
|
|
2031
|
+
"fsharp",
|
|
2032
|
+
"typescript",
|
|
2033
|
+
"javascript"
|
|
2034
|
+
],
|
|
2035
|
+
"definitionChecking": true,
|
|
2036
|
+
"nativeExecution": "deferred",
|
|
2037
|
+
"apiCollectionCredit": "deferred: this story is not a complete public API collection"
|
|
2038
|
+
},
|
|
2039
|
+
"implementationSyntax": {
|
|
2040
|
+
"fsharp": "In F#, rows: int annotates the input. rows * 4 is an integer expression and can be the function’s result without a return keyword.",
|
|
2041
|
+
"typescript": "In TypeScript, rows: number annotates the input. return rows * 4 computes the total from the row count.",
|
|
2042
|
+
"javascript": "In JavaScript, rows names the input. return rows * 4 computes the total from that count."
|
|
2043
|
+
},
|
|
2044
|
+
"naming": "Use English phrase names for readable claims and descriptive LawSpec helpers. Keep short code names such as add, sort, xs and numbers when they make calls and recipes easier to follow. A phrase starts with \"| and ends with |, without a closing quote. A law label identifies the claim; renaming it does not change what the definition checks. The compiler generates target-appropriate names.",
|
|
2045
|
+
"projects": {
|
|
2046
|
+
"fsharp": {
|
|
2047
|
+
"Solution.fs": "module Solution\n\n// One row has four seats. This implementation knows only our examples.\nlet seats (rows: int) : int =\n if rows = 1 then 4\n elif rows = 2 then 8\n else 0\n",
|
|
2048
|
+
"Tests.lawspec": "-- ref:DEC-learn-tests-in-lawspec\nunit learn.seats\nseats :: Int32 -> Int32\n\nlaw \"|one row has four seats| is\n definition:\n seats 1 = 4\n end definition\nend law\n\nlaw \"|two rows have eight seats| is\n definition:\n seats 2 = 8\n end definition\nend law\n\nend unit\n",
|
|
2049
|
+
"Harness.lawspec": "harness learn.seats.testing for learn.seats is\n -- This step checks concrete inputs; no generator is selected.\nend harness\n"
|
|
2050
|
+
},
|
|
2051
|
+
"typescript": {
|
|
2052
|
+
"Solution.ts": "export function seats(rows: number): number\n{\n return rows === 1 ? 4 : rows === 2 ? 8 : 0;\n}\n",
|
|
2053
|
+
"Tests.lawspec": "-- ref:DEC-learn-tests-in-lawspec\nunit learn.seats\nseats :: Int32 -> Int32\n\nlaw \"|one row has four seats| is\n definition:\n seats 1 = 4\n end definition\nend law\n\nlaw \"|two rows have eight seats| is\n definition:\n seats 2 = 8\n end definition\nend law\n\nend unit\n",
|
|
2054
|
+
"Harness.lawspec": "harness learn.seats.testing for learn.seats is\n -- This step checks concrete inputs; no generator is selected.\nend harness\n"
|
|
2055
|
+
},
|
|
2056
|
+
"javascript": {
|
|
2057
|
+
"Solution.js": "export function seats(rows)\n{\n return rows === 1 ? 4 : rows === 2 ? 8 : 0;\n}\n",
|
|
2058
|
+
"Tests.lawspec": "-- ref:DEC-learn-tests-in-lawspec\nunit learn.seats\nseats :: Int32 -> Int32\n\nlaw \"|one row has four seats| is\n definition:\n seats 1 = 4\n end definition\nend law\n\nlaw \"|two rows have eight seats| is\n definition:\n seats 2 = 8\n end definition\nend law\n\nend unit\n",
|
|
2059
|
+
"Harness.lawspec": "harness learn.seats.testing for learn.seats is\n -- This step checks concrete inputs; no generator is selected.\nend harness\n"
|
|
2060
|
+
}
|
|
2061
|
+
},
|
|
2062
|
+
"solutions": {
|
|
2063
|
+
"fsharp": {
|
|
2064
|
+
"Solution.fs": "module Solution\n\nlet seats (rows: int) : int = rows * 4\n",
|
|
2065
|
+
"Tests.lawspec": "-- ref:DEC-learn-tests-in-lawspec\nunit learn.seats\nseats :: Int32 -> Int32\n\nlaw \"|one row has four seats| is\n definition:\n seats 1 = 4\n end definition\nend law\n\nlaw \"|two rows have eight seats| is\n definition:\n seats 2 = 8\n end definition\nend law\n\nlaw \"|three rows have twelve seats| is\n definition:\n seats 3 = 12\n end definition\nend law\n\nlaw \"|every row contributes four seats| is\n definition:\n for all (rows :: Int32 where rows >= 0 and rows <= 40) =>\n seats rows = rows * 4\n end for all\n end definition\nend law\n\nend unit\n",
|
|
2066
|
+
"Harness.lawspec": "harness learn.seats.testing for learn.seats is\n strategy numbers :: (n :: Int32 where n >= 0 and n <= 40) is any end strategy\n for law \"|every row contributes four seats|\n use numbers for rows\n end for law\nend harness\n"
|
|
2067
|
+
},
|
|
2068
|
+
"typescript": {
|
|
2069
|
+
"Solution.ts": "export function seats(rows: number): number\n{\n return rows * 4;\n}\n",
|
|
2070
|
+
"Tests.lawspec": "-- ref:DEC-learn-tests-in-lawspec\nunit learn.seats\nseats :: Int32 -> Int32\n\nlaw \"|one row has four seats| is\n definition:\n seats 1 = 4\n end definition\nend law\n\nlaw \"|two rows have eight seats| is\n definition:\n seats 2 = 8\n end definition\nend law\n\nlaw \"|three rows have twelve seats| is\n definition:\n seats 3 = 12\n end definition\nend law\n\nlaw \"|every row contributes four seats| is\n definition:\n for all (rows :: Int32 where rows >= 0 and rows <= 40) =>\n seats rows = rows * 4\n end for all\n end definition\nend law\n\nend unit\n",
|
|
2071
|
+
"Harness.lawspec": "harness learn.seats.testing for learn.seats is\n strategy numbers :: (n :: Int32 where n >= 0 and n <= 40) is any end strategy\n for law \"|every row contributes four seats|\n use numbers for rows\n end for law\nend harness\n"
|
|
2072
|
+
},
|
|
2073
|
+
"javascript": {
|
|
2074
|
+
"Solution.js": "export function seats(rows)\n{\n return rows * 4;\n}\n",
|
|
2075
|
+
"Tests.lawspec": "-- ref:DEC-learn-tests-in-lawspec\nunit learn.seats\nseats :: Int32 -> Int32\n\nlaw \"|one row has four seats| is\n definition:\n seats 1 = 4\n end definition\nend law\n\nlaw \"|two rows have eight seats| is\n definition:\n seats 2 = 8\n end definition\nend law\n\nlaw \"|three rows have twelve seats| is\n definition:\n seats 3 = 12\n end definition\nend law\n\nlaw \"|every row contributes four seats| is\n definition:\n for all (rows :: Int32 where rows >= 0 and rows <= 40) =>\n seats rows = rows * 4\n end for all\n end definition\nend law\n\nend unit\n",
|
|
2076
|
+
"Harness.lawspec": "harness learn.seats.testing for learn.seats is\n strategy numbers :: (n :: Int32 where n >= 0 and n <= 40) is any end strategy\n for law \"|every row contributes four seats|\n use numbers for rows\n end for law\nend harness\n"
|
|
2077
|
+
}
|
|
2078
|
+
},
|
|
2079
|
+
"solutionSources": {
|
|
2080
|
+
"fsharp": {
|
|
2081
|
+
"Tests.lawspec": "exercises/examples/solution/Tests.lawspec",
|
|
2082
|
+
"Harness.lawspec": "exercises/examples/solution/Harness.lawspec",
|
|
2083
|
+
"Solution.fs": "exercises/examples/solution/fsharp/Solution.fs"
|
|
2084
|
+
},
|
|
2085
|
+
"typescript": {
|
|
2086
|
+
"Tests.lawspec": "exercises/examples/solution/Tests.lawspec",
|
|
2087
|
+
"Harness.lawspec": "exercises/examples/solution/Harness.lawspec",
|
|
2088
|
+
"Solution.ts": "exercises/examples/solution/typescript/Solution.ts"
|
|
2089
|
+
},
|
|
2090
|
+
"javascript": {
|
|
2091
|
+
"Tests.lawspec": "exercises/examples/solution/Tests.lawspec",
|
|
2092
|
+
"Harness.lawspec": "exercises/examples/solution/Harness.lawspec",
|
|
2093
|
+
"Solution.js": "exercises/examples/solution/javascript/Solution.js"
|
|
2094
|
+
}
|
|
2095
|
+
}
|
|
2096
|
+
},
|
|
2097
|
+
{
|
|
2098
|
+
"id": "weak-properties",
|
|
2099
|
+
"title": "Practice: keep every library request",
|
|
2100
|
+
"section": "Apply the ideas",
|
|
2101
|
+
"vision": "Apply ordering and preservation to a library queue where equal priorities still represent different requests.",
|
|
2102
|
+
"slogan": "Same priority, separate requests.",
|
|
2103
|
+
"symbol": "[3, 1, 1] → [1, 1, 3]: both 1s stay",
|
|
2104
|
+
"explanation": "Laws and generation strategies are authored in LawSpec. Only the implementation changes language.",
|
|
2105
|
+
"news": "Equal priority values can represent separate requests that must both survive.",
|
|
2106
|
+
"contributions": "A library queue sorter with ordering and occurrence preservation. Duplicate requests survive; replacing requests with zeros fails even when the output length is right.",
|
|
2107
|
+
"star": {
|
|
2108
|
+
"salient": "Equal priority values can represent separate requests that must both survive.",
|
|
2109
|
+
"slogan": "Same priority, separate requests.",
|
|
2110
|
+
"symbol": "[3, 1, 1] → [1, 1, 3]: both 1s stay",
|
|
2111
|
+
"surprise": "A queue can have the right length and be ordered while every priority has been replaced.",
|
|
2112
|
+
"story": "The library needs requests ordered by priority. Empty output, deduplication and invented zero priorities all lose the meaning of the queue; a correct sort preserves every request’s rank."
|
|
2113
|
+
},
|
|
2114
|
+
"attribution": [
|
|
2115
|
+
{
|
|
2116
|
+
"title": "Scott Wlaschin — Choosing properties in practice, part 1",
|
|
2117
|
+
"url": "https://fsharpforfunandprofit.com/posts/property-based-testing-3/",
|
|
2118
|
+
"use": "Original library application after the sorting examples."
|
|
2119
|
+
}
|
|
2120
|
+
],
|
|
2121
|
+
"hints": [
|
|
2122
|
+
"Each integer is one request’s rank. How many requests share rank 1 in the failing example?",
|
|
2123
|
+
"Removing equal values removes requests. Count them before considering order.",
|
|
2124
|
+
"Sort the original ranks without discarding or replacing them. Load solution reveals the full repair."
|
|
2125
|
+
],
|
|
2126
|
+
"stages": [
|
|
2127
|
+
{
|
|
2128
|
+
"id": "empty",
|
|
2129
|
+
"title": "What does one number in the queue mean?",
|
|
2130
|
+
"story": [
|
|
2131
|
+
"A library serves requests by priority. For this exercise, each integer represents one request’s priority rank; a lower rank comes first. Two requests can have the same rank. They are still two requests.",
|
|
2132
|
+
"The task is to reorder these ranks without dropping or inventing a request. By the end, you will have applied both parts of the sorting contract to that practical meaning.",
|
|
2133
|
+
"The current implementation returns an empty queue, and Laws asks only whether its output is ordered. Predict whether that check rejects it, then run checks with All checks. An empty result has no out-of-order pair, but nobody remains in the queue."
|
|
2134
|
+
],
|
|
2135
|
+
"focus": "Solution",
|
|
2136
|
+
"project": "exercises/weak-properties/01",
|
|
2137
|
+
"run": {
|
|
2138
|
+
"mode": "all",
|
|
2139
|
+
"expect": "passed",
|
|
2140
|
+
"seed": 424242
|
|
2141
|
+
},
|
|
2142
|
+
"action": "Run the ordering-only suite. Explain what each of the two 1s represents and why [] fails the library’s task.",
|
|
2143
|
+
"reason": "Priority is the sorting key, not a request identity. Equal keys do not authorize deleting a request.",
|
|
2144
|
+
"expect": "The supplied code compiles and the selected checks pass. Read which checks actually ran before interpreting this result.",
|
|
2145
|
+
"recovery": "Reset this step restores its supplied files and seed. After an edit, use the actual result to judge your version; the story’s prediction describes the supplied files.",
|
|
2146
|
+
"editor": "Tests",
|
|
2147
|
+
"syntax": "the ordering helper checks the rank sequence. It cannot count whether the original requests survived.",
|
|
2148
|
+
"harnessNotes": [
|
|
2149
|
+
"number draws integers from -20 through 20. The short-list strategy draws a, b and c from number using nested bind expressions: each bind makes its drawn value available inside the following expression.",
|
|
2150
|
+
"one of chooses between [], [a], [a, b] and [a, b, c]. These are lists of zero through three items; repeated values are possible. This recipe does not generate arbitrary-length lists. Shrinking can try smaller choices and smaller elements, keeping only candidates that still fail.",
|
|
2151
|
+
"The binding for “the result is in ascending order” selects the claim in Laws; use lists for xs supplies its list input xs. The implementation returns a result, and the law checks it. The generator does not provide the expected answer."
|
|
2152
|
+
],
|
|
2153
|
+
"symbol": "[3, 1, 1] → [1, 1, 3]: both 1s stay",
|
|
2154
|
+
"projects": {
|
|
2155
|
+
"fsharp": {
|
|
2156
|
+
"Solution.fs": "module Solution\n\nlet sort (xs: int list) : int list = []\n",
|
|
2157
|
+
"Tests.lawspec": "-- ref:DEC-learn-tests-in-lawspec\nunit learn.sorting\nsort :: List Int32 -> List Int32\n\nfunction \"|is in ascending order| (xs :: List Int32) -> Bool is\n first matching case of xs :\n when Nil then true\n when Cons h t then\n (first matching case of t :\n when Nil then true\n when Cons next rest then h <= next and \"|is in ascending order| t\n end case)\n end case\nend function\n\nlaw \"|an empty input stays empty| is\n definition:\n sort [] = []\n end definition\nend law\n\nlaw \"|the result is in ascending order| is\n definition:\n for all (xs :: List Int32) =>\n \"|is in ascending order| (sort xs) = true\n end for all\n end definition\nend law\n\nend unit\n",
|
|
2158
|
+
"Harness.lawspec": "harness learn.sorting.testing for learn.sorting is\n strategy number :: (n :: Int32 where n >= -20 and n <= 20) is any end strategy\n\n -- Draw up to three items constructively; shrinking follows these choices.\n strategy lists :: List Int32 is\n bind a :: Int32 from number in\n bind b :: Int32 from number in\n bind c :: Int32 from number in\n one of [], [a], [a, b], [a, b, c]\n end bind end bind end bind\n end strategy\n\n for law \"|the result is in ascending order|\n use lists for xs\n end for law\nend harness\n"
|
|
2159
|
+
},
|
|
2160
|
+
"typescript": {
|
|
2161
|
+
"Solution.ts": "export function sort(xs: number[]): number[]\n{\n return [];\n}\n",
|
|
2162
|
+
"Tests.lawspec": "-- ref:DEC-learn-tests-in-lawspec\nunit learn.sorting\nsort :: List Int32 -> List Int32\n\nfunction \"|is in ascending order| (xs :: List Int32) -> Bool is\n first matching case of xs :\n when Nil then true\n when Cons h t then\n (first matching case of t :\n when Nil then true\n when Cons next rest then h <= next and \"|is in ascending order| t\n end case)\n end case\nend function\n\nlaw \"|an empty input stays empty| is\n definition:\n sort [] = []\n end definition\nend law\n\nlaw \"|the result is in ascending order| is\n definition:\n for all (xs :: List Int32) =>\n \"|is in ascending order| (sort xs) = true\n end for all\n end definition\nend law\n\nend unit\n",
|
|
2163
|
+
"Harness.lawspec": "harness learn.sorting.testing for learn.sorting is\n strategy number :: (n :: Int32 where n >= -20 and n <= 20) is any end strategy\n\n -- Draw up to three items constructively; shrinking follows these choices.\n strategy lists :: List Int32 is\n bind a :: Int32 from number in\n bind b :: Int32 from number in\n bind c :: Int32 from number in\n one of [], [a], [a, b], [a, b, c]\n end bind end bind end bind\n end strategy\n\n for law \"|the result is in ascending order|\n use lists for xs\n end for law\nend harness\n"
|
|
2164
|
+
},
|
|
2165
|
+
"javascript": {
|
|
2166
|
+
"Solution.js": "export function sort(xs)\n{\n return [];\n}\n",
|
|
2167
|
+
"Tests.lawspec": "-- ref:DEC-learn-tests-in-lawspec\nunit learn.sorting\nsort :: List Int32 -> List Int32\n\nfunction \"|is in ascending order| (xs :: List Int32) -> Bool is\n first matching case of xs :\n when Nil then true\n when Cons h t then\n (first matching case of t :\n when Nil then true\n when Cons next rest then h <= next and \"|is in ascending order| t\n end case)\n end case\nend function\n\nlaw \"|an empty input stays empty| is\n definition:\n sort [] = []\n end definition\nend law\n\nlaw \"|the result is in ascending order| is\n definition:\n for all (xs :: List Int32) =>\n \"|is in ascending order| (sort xs) = true\n end for all\n end definition\nend law\n\nend unit\n",
|
|
2168
|
+
"Harness.lawspec": "harness learn.sorting.testing for learn.sorting is\n strategy number :: (n :: Int32 where n >= -20 and n <= 20) is any end strategy\n\n -- Draw up to three items constructively; shrinking follows these choices.\n strategy lists :: List Int32 is\n bind a :: Int32 from number in\n bind b :: Int32 from number in\n bind c :: Int32 from number in\n one of [], [a], [a, b], [a, b, c]\n end bind end bind end bind\n end strategy\n\n for law \"|the result is in ascending order|\n use lists for xs\n end for law\nend harness\n"
|
|
2169
|
+
}
|
|
2170
|
+
},
|
|
2171
|
+
"sources": {
|
|
2172
|
+
"fsharp": {
|
|
2173
|
+
"Tests.lawspec": "exercises/weak-properties/01/Tests.lawspec",
|
|
2174
|
+
"Harness.lawspec": "exercises/weak-properties/01/Harness.lawspec",
|
|
2175
|
+
"Solution.fs": "exercises/weak-properties/01/fsharp/Solution.fs"
|
|
2176
|
+
},
|
|
2177
|
+
"typescript": {
|
|
2178
|
+
"Tests.lawspec": "exercises/weak-properties/01/Tests.lawspec",
|
|
2179
|
+
"Harness.lawspec": "exercises/weak-properties/01/Harness.lawspec",
|
|
2180
|
+
"Solution.ts": "exercises/weak-properties/01/typescript/Solution.ts"
|
|
2181
|
+
},
|
|
2182
|
+
"javascript": {
|
|
2183
|
+
"Tests.lawspec": "exercises/weak-properties/01/Tests.lawspec",
|
|
2184
|
+
"Harness.lawspec": "exercises/weak-properties/01/Harness.lawspec",
|
|
2185
|
+
"Solution.js": "exercises/weak-properties/01/javascript/Solution.js"
|
|
2186
|
+
}
|
|
2187
|
+
},
|
|
2188
|
+
"previousProjects": {
|
|
2189
|
+
"fsharp": {
|
|
2190
|
+
"Solution.fs": "module Solution\n\nlet sort (xs: int list) : int list = []\n",
|
|
2191
|
+
"Tests.lawspec": "-- ref:DEC-learn-tests-in-lawspec\nunit learn.sorting\nsort :: List Int32 -> List Int32\n\nfunction ordered (xs :: List Int32) -> Bool is\n first matching case of xs :\n when Nil then true\n when Cons h t then\n (first matching case of t :\n when Nil then true\n when Cons next rest then h <= next and ordered t\n end case)\n end case\nend function\n\nlaw emptyInput is\n definition:\n sort [] = []\n end definition\nend law\n\nlaw sortingRule is\n definition:\n for all (xs :: List Int32) => ordered (sort xs) = true end for all\n end definition\nend law\n\nend unit\n",
|
|
2192
|
+
"Harness.lawspec": "harness learn.sorting.testing for learn.sorting is\n strategy number :: (n :: Int32 where n >= -20 and n <= 20) is any end strategy\n\n -- Draw up to three items constructively; shrinking follows these choices.\n strategy lists :: List Int32 is\n bind a :: Int32 from number in\n bind b :: Int32 from number in\n bind c :: Int32 from number in\n one of [], [a], [a, b], [a, b, c]\n end bind end bind end bind\n end strategy\n\n for law sortingRule\n use lists for xs\n end for law\nend harness\n"
|
|
2193
|
+
},
|
|
2194
|
+
"typescript": {
|
|
2195
|
+
"Solution.ts": "export function sort(xs: number[]): number[]\n{\n return [];\n}\n",
|
|
2196
|
+
"Tests.lawspec": "-- ref:DEC-learn-tests-in-lawspec\nunit learn.sorting\nsort :: List Int32 -> List Int32\n\nfunction ordered (xs :: List Int32) -> Bool is\n first matching case of xs :\n when Nil then true\n when Cons h t then\n (first matching case of t :\n when Nil then true\n when Cons next rest then h <= next and ordered t\n end case)\n end case\nend function\n\nlaw emptyInput is\n definition:\n sort [] = []\n end definition\nend law\n\nlaw sortingRule is\n definition:\n for all (xs :: List Int32) => ordered (sort xs) = true end for all\n end definition\nend law\n\nend unit\n",
|
|
2197
|
+
"Harness.lawspec": "harness learn.sorting.testing for learn.sorting is\n strategy number :: (n :: Int32 where n >= -20 and n <= 20) is any end strategy\n\n -- Draw up to three items constructively; shrinking follows these choices.\n strategy lists :: List Int32 is\n bind a :: Int32 from number in\n bind b :: Int32 from number in\n bind c :: Int32 from number in\n one of [], [a], [a, b], [a, b, c]\n end bind end bind end bind\n end strategy\n\n for law sortingRule\n use lists for xs\n end for law\nend harness\n"
|
|
2198
|
+
},
|
|
2199
|
+
"javascript": {
|
|
2200
|
+
"Solution.js": "export function sort(xs)\n{\n return [];\n}\n",
|
|
2201
|
+
"Tests.lawspec": "-- ref:DEC-learn-tests-in-lawspec\nunit learn.sorting\nsort :: List Int32 -> List Int32\n\nfunction ordered (xs :: List Int32) -> Bool is\n first matching case of xs :\n when Nil then true\n when Cons h t then\n (first matching case of t :\n when Nil then true\n when Cons next rest then h <= next and ordered t\n end case)\n end case\nend function\n\nlaw emptyInput is\n definition:\n sort [] = []\n end definition\nend law\n\nlaw sortingRule is\n definition:\n for all (xs :: List Int32) => ordered (sort xs) = true end for all\n end definition\nend law\n\nend unit\n",
|
|
2202
|
+
"Harness.lawspec": "harness learn.sorting.testing for learn.sorting is\n strategy number :: (n :: Int32 where n >= -20 and n <= 20) is any end strategy\n\n -- Draw up to three items constructively; shrinking follows these choices.\n strategy lists :: List Int32 is\n bind a :: Int32 from number in\n bind b :: Int32 from number in\n bind c :: Int32 from number in\n one of [], [a], [a, b], [a, b, c]\n end bind end bind end bind\n end strategy\n\n for law sortingRule\n use lists for xs\n end for law\nend harness\n"
|
|
2203
|
+
}
|
|
2204
|
+
}
|
|
2205
|
+
},
|
|
2206
|
+
{
|
|
2207
|
+
"id": "duplicates",
|
|
2208
|
+
"title": "Two requests with one priority must both stay",
|
|
2209
|
+
"story": [
|
|
2210
|
+
"Laws now requires sameItems as well as ordered. The concrete “requests with equal priority both stay” check contains two requests with rank 1 and one with rank 3.",
|
|
2211
|
+
"Solution removes repeated values before sorting. That treats the two rank-1 requests as if they were the same request. Use Run checks with All checks: the result is ordered, but one request has disappeared.",
|
|
2212
|
+
"This is preservation: every input occurrence has a matching output occurrence. It is different from merely checking whether each distinct value appears somewhere."
|
|
2213
|
+
],
|
|
2214
|
+
"focus": "Tests",
|
|
2215
|
+
"project": "exercises/weak-properties/02",
|
|
2216
|
+
"run": {
|
|
2217
|
+
"mode": "all",
|
|
2218
|
+
"expect": "failed",
|
|
2219
|
+
"sampled": "failed",
|
|
2220
|
+
"seed": 424242
|
|
2221
|
+
},
|
|
2222
|
+
"action": "Use Run checks with All checks and count rank-1 requests in the input, expected result and actual result.",
|
|
2223
|
+
"reason": "Same priority, separate requests. Sorting a queue must preserve the count at each rank.",
|
|
2224
|
+
"expect": "The supplied code compiles, then the selected checks fail. A compiler error is a different problem; inspect diagnostics if execution did not start.",
|
|
2225
|
+
"recovery": "Reset this step restores its supplied files and seed. After an edit, use the actual result to judge your version; the story’s prediction describes the supplied files.",
|
|
2226
|
+
"editor": "Solution",
|
|
2227
|
+
"syntax": "sameItems compares occurrence counts. The two occurrences of 1 in “requests with equal priority both stay” are both required.",
|
|
2228
|
+
"harnessNotes": [
|
|
2229
|
+
"number draws integers from -20 through 20. The short-list strategy draws a, b and c from number using nested bind expressions: each bind makes its drawn value available inside the following expression.",
|
|
2230
|
+
"one of chooses between [], [a], [a, b] and [a, b, c]. These are lists of zero through three items; repeated values are possible. This recipe does not generate arbitrary-length lists. Shrinking can try smaller choices and smaller elements, keeping only candidates that still fail.",
|
|
2231
|
+
"The binding for “sorting orders values and keeps every occurrence” selects the claim in Laws; use lists for xs supplies its list input xs. The implementation returns a result, and the law checks it. The generator does not provide the expected answer."
|
|
2232
|
+
],
|
|
2233
|
+
"projects": {
|
|
2234
|
+
"fsharp": {
|
|
2235
|
+
"Solution.fs": "module Solution\n\nlet sort (xs: int list) : int list = List.distinct xs |> List.sort\n",
|
|
2236
|
+
"Tests.lawspec": "-- ref:DEC-learn-tests-in-lawspec\nunit learn.sorting\nsort :: List Int32 -> List Int32\n\nfunction \"|is in ascending order| (xs :: List Int32) -> Bool is\n first matching case of xs :\n when Nil then true\n when Cons h t then\n (first matching case of t :\n when Nil then true\n when Cons next rest then h <= next and \"|is in ascending order| t\n end case)\n end case\nend function\n\nlaw \"|an empty input stays empty| is\n definition:\n sort [] = []\n end definition\nend law\n\nlaw \"|requests with equal priority both stay| is\n definition:\n sort [3, 1, 1] = [1, 1, 3]\n end definition\nend law\n\nlaw \"|sorting orders values and keeps every occurrence| is\n definition:\n for all (xs :: List Int32) =>\n \"|is in ascending order| (sort xs) = true and sameItems (sort xs) xs\n end for all\n end definition\nend law\n\nend unit\n",
|
|
2237
|
+
"Harness.lawspec": "harness learn.sorting.testing for learn.sorting is\n strategy number :: (n :: Int32 where n >= -20 and n <= 20) is any end strategy\n\n -- Draw up to three items constructively; shrinking follows these choices.\n strategy lists :: List Int32 is\n bind a :: Int32 from number in\n bind b :: Int32 from number in\n bind c :: Int32 from number in\n one of [], [a], [a, b], [a, b, c]\n end bind end bind end bind\n end strategy\n\n for law \"|sorting orders values and keeps every occurrence|\n use lists for xs\n end for law\nend harness\n"
|
|
2238
|
+
},
|
|
2239
|
+
"typescript": {
|
|
2240
|
+
"Solution.ts": "export function sort(xs: number[]): number[]\n{\n return [...new Set(xs)].sort((a, b) => a - b);\n}\n",
|
|
2241
|
+
"Tests.lawspec": "-- ref:DEC-learn-tests-in-lawspec\nunit learn.sorting\nsort :: List Int32 -> List Int32\n\nfunction \"|is in ascending order| (xs :: List Int32) -> Bool is\n first matching case of xs :\n when Nil then true\n when Cons h t then\n (first matching case of t :\n when Nil then true\n when Cons next rest then h <= next and \"|is in ascending order| t\n end case)\n end case\nend function\n\nlaw \"|an empty input stays empty| is\n definition:\n sort [] = []\n end definition\nend law\n\nlaw \"|requests with equal priority both stay| is\n definition:\n sort [3, 1, 1] = [1, 1, 3]\n end definition\nend law\n\nlaw \"|sorting orders values and keeps every occurrence| is\n definition:\n for all (xs :: List Int32) =>\n \"|is in ascending order| (sort xs) = true and sameItems (sort xs) xs\n end for all\n end definition\nend law\n\nend unit\n",
|
|
2242
|
+
"Harness.lawspec": "harness learn.sorting.testing for learn.sorting is\n strategy number :: (n :: Int32 where n >= -20 and n <= 20) is any end strategy\n\n -- Draw up to three items constructively; shrinking follows these choices.\n strategy lists :: List Int32 is\n bind a :: Int32 from number in\n bind b :: Int32 from number in\n bind c :: Int32 from number in\n one of [], [a], [a, b], [a, b, c]\n end bind end bind end bind\n end strategy\n\n for law \"|sorting orders values and keeps every occurrence|\n use lists for xs\n end for law\nend harness\n"
|
|
2243
|
+
},
|
|
2244
|
+
"javascript": {
|
|
2245
|
+
"Solution.js": "export function sort(xs)\n{\n return [...new Set(xs)].sort((a, b) => a - b);\n}\n",
|
|
2246
|
+
"Tests.lawspec": "-- ref:DEC-learn-tests-in-lawspec\nunit learn.sorting\nsort :: List Int32 -> List Int32\n\nfunction \"|is in ascending order| (xs :: List Int32) -> Bool is\n first matching case of xs :\n when Nil then true\n when Cons h t then\n (first matching case of t :\n when Nil then true\n when Cons next rest then h <= next and \"|is in ascending order| t\n end case)\n end case\nend function\n\nlaw \"|an empty input stays empty| is\n definition:\n sort [] = []\n end definition\nend law\n\nlaw \"|requests with equal priority both stay| is\n definition:\n sort [3, 1, 1] = [1, 1, 3]\n end definition\nend law\n\nlaw \"|sorting orders values and keeps every occurrence| is\n definition:\n for all (xs :: List Int32) =>\n \"|is in ascending order| (sort xs) = true and sameItems (sort xs) xs\n end for all\n end definition\nend law\n\nend unit\n",
|
|
2247
|
+
"Harness.lawspec": "harness learn.sorting.testing for learn.sorting is\n strategy number :: (n :: Int32 where n >= -20 and n <= 20) is any end strategy\n\n -- Draw up to three items constructively; shrinking follows these choices.\n strategy lists :: List Int32 is\n bind a :: Int32 from number in\n bind b :: Int32 from number in\n bind c :: Int32 from number in\n one of [], [a], [a, b], [a, b, c]\n end bind end bind end bind\n end strategy\n\n for law \"|sorting orders values and keeps every occurrence|\n use lists for xs\n end for law\nend harness\n"
|
|
2248
|
+
}
|
|
2249
|
+
},
|
|
2250
|
+
"sources": {
|
|
2251
|
+
"fsharp": {
|
|
2252
|
+
"Tests.lawspec": "exercises/weak-properties/02/Tests.lawspec",
|
|
2253
|
+
"Harness.lawspec": "exercises/weak-properties/02/Harness.lawspec",
|
|
2254
|
+
"Solution.fs": "exercises/weak-properties/02/fsharp/Solution.fs"
|
|
2255
|
+
},
|
|
2256
|
+
"typescript": {
|
|
2257
|
+
"Tests.lawspec": "exercises/weak-properties/02/Tests.lawspec",
|
|
2258
|
+
"Harness.lawspec": "exercises/weak-properties/02/Harness.lawspec",
|
|
2259
|
+
"Solution.ts": "exercises/weak-properties/02/typescript/Solution.ts"
|
|
2260
|
+
},
|
|
2261
|
+
"javascript": {
|
|
2262
|
+
"Tests.lawspec": "exercises/weak-properties/02/Tests.lawspec",
|
|
2263
|
+
"Harness.lawspec": "exercises/weak-properties/02/Harness.lawspec",
|
|
2264
|
+
"Solution.js": "exercises/weak-properties/02/javascript/Solution.js"
|
|
2265
|
+
}
|
|
2266
|
+
},
|
|
2267
|
+
"previousProjects": {
|
|
2268
|
+
"fsharp": {
|
|
2269
|
+
"Solution.fs": "module Solution\n\nlet sort (xs: int list) : int list = List.distinct xs |> List.sort\n",
|
|
2270
|
+
"Tests.lawspec": "-- ref:DEC-learn-tests-in-lawspec\nunit learn.sorting\nsort :: List Int32 -> List Int32\n\nfunction ordered (xs :: List Int32) -> Bool is\n first matching case of xs :\n when Nil then true\n when Cons h t then\n (first matching case of t :\n when Nil then true\n when Cons next rest then h <= next and ordered t\n end case)\n end case\nend function\n\nlaw emptyInput is\n definition:\n sort [] = []\n end definition\nend law\n\nlaw duplicateRequests is\n definition:\n sort [3, 1, 1] = [1, 1, 3]\n end definition\nend law\n\nlaw sortingRule is\n definition:\n for all (xs :: List Int32) => ordered (sort xs) = true and sameItems (sort\n xs) xs end for all\n end definition\nend law\n\nend unit\n",
|
|
2271
|
+
"Harness.lawspec": "harness learn.sorting.testing for learn.sorting is\n strategy number :: (n :: Int32 where n >= -20 and n <= 20) is any end strategy\n\n -- Draw up to three items constructively; shrinking follows these choices.\n strategy lists :: List Int32 is\n bind a :: Int32 from number in\n bind b :: Int32 from number in\n bind c :: Int32 from number in\n one of [], [a], [a, b], [a, b, c]\n end bind end bind end bind\n end strategy\n\n for law sortingRule\n use lists for xs\n end for law\nend harness\n"
|
|
2272
|
+
},
|
|
2273
|
+
"typescript": {
|
|
2274
|
+
"Solution.ts": "export function sort(xs: number[]): number[]\n{\n return [...new Set(xs)].sort((a, b) => a - b);\n}\n",
|
|
2275
|
+
"Tests.lawspec": "-- ref:DEC-learn-tests-in-lawspec\nunit learn.sorting\nsort :: List Int32 -> List Int32\n\nfunction ordered (xs :: List Int32) -> Bool is\n first matching case of xs :\n when Nil then true\n when Cons h t then\n (first matching case of t :\n when Nil then true\n when Cons next rest then h <= next and ordered t\n end case)\n end case\nend function\n\nlaw emptyInput is\n definition:\n sort [] = []\n end definition\nend law\n\nlaw duplicateRequests is\n definition:\n sort [3, 1, 1] = [1, 1, 3]\n end definition\nend law\n\nlaw sortingRule is\n definition:\n for all (xs :: List Int32) => ordered (sort xs) = true and sameItems (sort\n xs) xs end for all\n end definition\nend law\n\nend unit\n",
|
|
2276
|
+
"Harness.lawspec": "harness learn.sorting.testing for learn.sorting is\n strategy number :: (n :: Int32 where n >= -20 and n <= 20) is any end strategy\n\n -- Draw up to three items constructively; shrinking follows these choices.\n strategy lists :: List Int32 is\n bind a :: Int32 from number in\n bind b :: Int32 from number in\n bind c :: Int32 from number in\n one of [], [a], [a, b], [a, b, c]\n end bind end bind end bind\n end strategy\n\n for law sortingRule\n use lists for xs\n end for law\nend harness\n"
|
|
2277
|
+
},
|
|
2278
|
+
"javascript": {
|
|
2279
|
+
"Solution.js": "export function sort(xs)\n{\n return [...new Set(xs)].sort((a, b) => a - b);\n}\n",
|
|
2280
|
+
"Tests.lawspec": "-- ref:DEC-learn-tests-in-lawspec\nunit learn.sorting\nsort :: List Int32 -> List Int32\n\nfunction ordered (xs :: List Int32) -> Bool is\n first matching case of xs :\n when Nil then true\n when Cons h t then\n (first matching case of t :\n when Nil then true\n when Cons next rest then h <= next and ordered t\n end case)\n end case\nend function\n\nlaw emptyInput is\n definition:\n sort [] = []\n end definition\nend law\n\nlaw duplicateRequests is\n definition:\n sort [3, 1, 1] = [1, 1, 3]\n end definition\nend law\n\nlaw sortingRule is\n definition:\n for all (xs :: List Int32) => ordered (sort xs) = true and sameItems (sort\n xs) xs end for all\n end definition\nend law\n\nend unit\n",
|
|
2281
|
+
"Harness.lawspec": "harness learn.sorting.testing for learn.sorting is\n strategy number :: (n :: Int32 where n >= -20 and n <= 20) is any end strategy\n\n -- Draw up to three items constructively; shrinking follows these choices.\n strategy lists :: List Int32 is\n bind a :: Int32 from number in\n bind b :: Int32 from number in\n bind c :: Int32 from number in\n one of [], [a], [a, b], [a, b, c]\n end bind end bind end bind\n end strategy\n\n for law sortingRule\n use lists for xs\n end for law\nend harness\n"
|
|
2282
|
+
}
|
|
2283
|
+
}
|
|
2284
|
+
},
|
|
2285
|
+
{
|
|
2286
|
+
"id": "substitute",
|
|
2287
|
+
"title": "Invented priorities are not preservation",
|
|
2288
|
+
"story": [
|
|
2289
|
+
"This implementation returns a zero for every input item. It keeps the number of positions, and those zeros are ordered.",
|
|
2290
|
+
"The requests’ priority ranks have been replaced. Run the unchanged suite and inspect which counts disagree. The sameItems requirement catches this without adding a special rule against zero."
|
|
2291
|
+
],
|
|
2292
|
+
"focus": "Solution",
|
|
2293
|
+
"project": "exercises/weak-properties/03",
|
|
2294
|
+
"run": {
|
|
2295
|
+
"mode": "all",
|
|
2296
|
+
"expect": "failed",
|
|
2297
|
+
"sampled": "failed",
|
|
2298
|
+
"seed": 424242
|
|
2299
|
+
},
|
|
2300
|
+
"action": "Run the suite and explain why matching the queue length does not preserve its requests’ ranks.",
|
|
2301
|
+
"reason": "Preserving a queue means retaining its values and their counts, as well as its length.",
|
|
2302
|
+
"expect": "The supplied code compiles, then the selected checks fail. A compiler error is a different problem; inspect diagnostics if execution did not start.",
|
|
2303
|
+
"recovery": "Reset this step restores its supplied files and seed. After an edit, use the actual result to judge your version; the story’s prediction describes the supplied files.",
|
|
2304
|
+
"editor": "Tests",
|
|
2305
|
+
"syntax": "sameItems rules out substitution as well as deletion. Zero is an ordinary integer here; the problem is replacing input values with it.",
|
|
2306
|
+
"harnessNotes": [
|
|
2307
|
+
"number draws integers from -20 through 20. The short-list strategy draws a, b and c from number using nested bind expressions: each bind makes its drawn value available inside the following expression.",
|
|
2308
|
+
"one of chooses between [], [a], [a, b] and [a, b, c]. These are lists of zero through three items; repeated values are possible. This recipe does not generate arbitrary-length lists. Shrinking can try smaller choices and smaller elements, keeping only candidates that still fail.",
|
|
2309
|
+
"The binding for “sorting orders values and keeps every occurrence” selects the claim in Laws; use lists for xs supplies its list input xs. The implementation returns a result, and the law checks it. The generator does not provide the expected answer."
|
|
2310
|
+
],
|
|
2311
|
+
"projects": {
|
|
2312
|
+
"fsharp": {
|
|
2313
|
+
"Solution.fs": "module Solution\n\nlet sort (xs: int list) : int list = List.map (fun _ -> 0) xs\n",
|
|
2314
|
+
"Tests.lawspec": "-- ref:DEC-learn-tests-in-lawspec\nunit learn.sorting\nsort :: List Int32 -> List Int32\n\nfunction \"|is in ascending order| (xs :: List Int32) -> Bool is\n first matching case of xs :\n when Nil then true\n when Cons h t then\n (first matching case of t :\n when Nil then true\n when Cons next rest then h <= next and \"|is in ascending order| t\n end case)\n end case\nend function\n\nlaw \"|an empty input stays empty| is\n definition:\n sort [] = []\n end definition\nend law\n\nlaw \"|requests with equal priority both stay| is\n definition:\n sort [3, 1, 1] = [1, 1, 3]\n end definition\nend law\n\nlaw \"|sorting orders values and keeps every occurrence| is\n definition:\n for all (xs :: List Int32) =>\n \"|is in ascending order| (sort xs) = true and sameItems (sort xs) xs\n end for all\n end definition\nend law\n\nend unit\n",
|
|
2315
|
+
"Harness.lawspec": "harness learn.sorting.testing for learn.sorting is\n strategy number :: (n :: Int32 where n >= -20 and n <= 20) is any end strategy\n\n -- Draw up to three items constructively; shrinking follows these choices.\n strategy lists :: List Int32 is\n bind a :: Int32 from number in\n bind b :: Int32 from number in\n bind c :: Int32 from number in\n one of [], [a], [a, b], [a, b, c]\n end bind end bind end bind\n end strategy\n\n for law \"|sorting orders values and keeps every occurrence|\n use lists for xs\n end for law\nend harness\n"
|
|
2316
|
+
},
|
|
2317
|
+
"typescript": {
|
|
2318
|
+
"Solution.ts": "export function sort(xs: number[]): number[]\n{\n return xs.map(() => 0);\n}\n",
|
|
2319
|
+
"Tests.lawspec": "-- ref:DEC-learn-tests-in-lawspec\nunit learn.sorting\nsort :: List Int32 -> List Int32\n\nfunction \"|is in ascending order| (xs :: List Int32) -> Bool is\n first matching case of xs :\n when Nil then true\n when Cons h t then\n (first matching case of t :\n when Nil then true\n when Cons next rest then h <= next and \"|is in ascending order| t\n end case)\n end case\nend function\n\nlaw \"|an empty input stays empty| is\n definition:\n sort [] = []\n end definition\nend law\n\nlaw \"|requests with equal priority both stay| is\n definition:\n sort [3, 1, 1] = [1, 1, 3]\n end definition\nend law\n\nlaw \"|sorting orders values and keeps every occurrence| is\n definition:\n for all (xs :: List Int32) =>\n \"|is in ascending order| (sort xs) = true and sameItems (sort xs) xs\n end for all\n end definition\nend law\n\nend unit\n",
|
|
2320
|
+
"Harness.lawspec": "harness learn.sorting.testing for learn.sorting is\n strategy number :: (n :: Int32 where n >= -20 and n <= 20) is any end strategy\n\n -- Draw up to three items constructively; shrinking follows these choices.\n strategy lists :: List Int32 is\n bind a :: Int32 from number in\n bind b :: Int32 from number in\n bind c :: Int32 from number in\n one of [], [a], [a, b], [a, b, c]\n end bind end bind end bind\n end strategy\n\n for law \"|sorting orders values and keeps every occurrence|\n use lists for xs\n end for law\nend harness\n"
|
|
2321
|
+
},
|
|
2322
|
+
"javascript": {
|
|
2323
|
+
"Solution.js": "export function sort(xs)\n{\n return xs.map(() => 0);\n}\n",
|
|
2324
|
+
"Tests.lawspec": "-- ref:DEC-learn-tests-in-lawspec\nunit learn.sorting\nsort :: List Int32 -> List Int32\n\nfunction \"|is in ascending order| (xs :: List Int32) -> Bool is\n first matching case of xs :\n when Nil then true\n when Cons h t then\n (first matching case of t :\n when Nil then true\n when Cons next rest then h <= next and \"|is in ascending order| t\n end case)\n end case\nend function\n\nlaw \"|an empty input stays empty| is\n definition:\n sort [] = []\n end definition\nend law\n\nlaw \"|requests with equal priority both stay| is\n definition:\n sort [3, 1, 1] = [1, 1, 3]\n end definition\nend law\n\nlaw \"|sorting orders values and keeps every occurrence| is\n definition:\n for all (xs :: List Int32) =>\n \"|is in ascending order| (sort xs) = true and sameItems (sort xs) xs\n end for all\n end definition\nend law\n\nend unit\n",
|
|
2325
|
+
"Harness.lawspec": "harness learn.sorting.testing for learn.sorting is\n strategy number :: (n :: Int32 where n >= -20 and n <= 20) is any end strategy\n\n -- Draw up to three items constructively; shrinking follows these choices.\n strategy lists :: List Int32 is\n bind a :: Int32 from number in\n bind b :: Int32 from number in\n bind c :: Int32 from number in\n one of [], [a], [a, b], [a, b, c]\n end bind end bind end bind\n end strategy\n\n for law \"|sorting orders values and keeps every occurrence|\n use lists for xs\n end for law\nend harness\n"
|
|
2326
|
+
}
|
|
2327
|
+
},
|
|
2328
|
+
"sources": {
|
|
2329
|
+
"fsharp": {
|
|
2330
|
+
"Tests.lawspec": "exercises/weak-properties/03/Tests.lawspec",
|
|
2331
|
+
"Harness.lawspec": "exercises/weak-properties/03/Harness.lawspec",
|
|
2332
|
+
"Solution.fs": "exercises/weak-properties/03/fsharp/Solution.fs"
|
|
2333
|
+
},
|
|
2334
|
+
"typescript": {
|
|
2335
|
+
"Tests.lawspec": "exercises/weak-properties/03/Tests.lawspec",
|
|
2336
|
+
"Harness.lawspec": "exercises/weak-properties/03/Harness.lawspec",
|
|
2337
|
+
"Solution.ts": "exercises/weak-properties/03/typescript/Solution.ts"
|
|
2338
|
+
},
|
|
2339
|
+
"javascript": {
|
|
2340
|
+
"Tests.lawspec": "exercises/weak-properties/03/Tests.lawspec",
|
|
2341
|
+
"Harness.lawspec": "exercises/weak-properties/03/Harness.lawspec",
|
|
2342
|
+
"Solution.js": "exercises/weak-properties/03/javascript/Solution.js"
|
|
2343
|
+
}
|
|
2344
|
+
},
|
|
2345
|
+
"previousProjects": {
|
|
2346
|
+
"fsharp": {
|
|
2347
|
+
"Solution.fs": "module Solution\n\nlet sort (xs: int list) : int list = List.map (fun _ -> 0) xs\n",
|
|
2348
|
+
"Tests.lawspec": "-- ref:DEC-learn-tests-in-lawspec\nunit learn.sorting\nsort :: List Int32 -> List Int32\n\nfunction ordered (xs :: List Int32) -> Bool is\n first matching case of xs :\n when Nil then true\n when Cons h t then\n (first matching case of t :\n when Nil then true\n when Cons next rest then h <= next and ordered t\n end case)\n end case\nend function\n\nlaw emptyInput is\n definition:\n sort [] = []\n end definition\nend law\n\nlaw duplicateRequests is\n definition:\n sort [3, 1, 1] = [1, 1, 3]\n end definition\nend law\n\nlaw sortingRule is\n definition:\n for all (xs :: List Int32) => ordered (sort xs) = true and sameItems (sort\n xs) xs end for all\n end definition\nend law\n\nend unit\n",
|
|
2349
|
+
"Harness.lawspec": "harness learn.sorting.testing for learn.sorting is\n strategy number :: (n :: Int32 where n >= -20 and n <= 20) is any end strategy\n\n -- Draw up to three items constructively; shrinking follows these choices.\n strategy lists :: List Int32 is\n bind a :: Int32 from number in\n bind b :: Int32 from number in\n bind c :: Int32 from number in\n one of [], [a], [a, b], [a, b, c]\n end bind end bind end bind\n end strategy\n\n for law sortingRule\n use lists for xs\n end for law\nend harness\n"
|
|
2350
|
+
},
|
|
2351
|
+
"typescript": {
|
|
2352
|
+
"Solution.ts": "export function sort(xs: number[]): number[]\n{\n return xs.map(() => 0);\n}\n",
|
|
2353
|
+
"Tests.lawspec": "-- ref:DEC-learn-tests-in-lawspec\nunit learn.sorting\nsort :: List Int32 -> List Int32\n\nfunction ordered (xs :: List Int32) -> Bool is\n first matching case of xs :\n when Nil then true\n when Cons h t then\n (first matching case of t :\n when Nil then true\n when Cons next rest then h <= next and ordered t\n end case)\n end case\nend function\n\nlaw emptyInput is\n definition:\n sort [] = []\n end definition\nend law\n\nlaw duplicateRequests is\n definition:\n sort [3, 1, 1] = [1, 1, 3]\n end definition\nend law\n\nlaw sortingRule is\n definition:\n for all (xs :: List Int32) => ordered (sort xs) = true and sameItems (sort\n xs) xs end for all\n end definition\nend law\n\nend unit\n",
|
|
2354
|
+
"Harness.lawspec": "harness learn.sorting.testing for learn.sorting is\n strategy number :: (n :: Int32 where n >= -20 and n <= 20) is any end strategy\n\n -- Draw up to three items constructively; shrinking follows these choices.\n strategy lists :: List Int32 is\n bind a :: Int32 from number in\n bind b :: Int32 from number in\n bind c :: Int32 from number in\n one of [], [a], [a, b], [a, b, c]\n end bind end bind end bind\n end strategy\n\n for law sortingRule\n use lists for xs\n end for law\nend harness\n"
|
|
2355
|
+
},
|
|
2356
|
+
"javascript": {
|
|
2357
|
+
"Solution.js": "export function sort(xs)\n{\n return xs.map(() => 0);\n}\n",
|
|
2358
|
+
"Tests.lawspec": "-- ref:DEC-learn-tests-in-lawspec\nunit learn.sorting\nsort :: List Int32 -> List Int32\n\nfunction ordered (xs :: List Int32) -> Bool is\n first matching case of xs :\n when Nil then true\n when Cons h t then\n (first matching case of t :\n when Nil then true\n when Cons next rest then h <= next and ordered t\n end case)\n end case\nend function\n\nlaw emptyInput is\n definition:\n sort [] = []\n end definition\nend law\n\nlaw duplicateRequests is\n definition:\n sort [3, 1, 1] = [1, 1, 3]\n end definition\nend law\n\nlaw sortingRule is\n definition:\n for all (xs :: List Int32) => ordered (sort xs) = true and sameItems (sort\n xs) xs end for all\n end definition\nend law\n\nend unit\n",
|
|
2359
|
+
"Harness.lawspec": "harness learn.sorting.testing for learn.sorting is\n strategy number :: (n :: Int32 where n >= -20 and n <= 20) is any end strategy\n\n -- Draw up to three items constructively; shrinking follows these choices.\n strategy lists :: List Int32 is\n bind a :: Int32 from number in\n bind b :: Int32 from number in\n bind c :: Int32 from number in\n one of [], [a], [a, b], [a, b, c]\n end bind end bind end bind\n end strategy\n\n for law sortingRule\n use lists for xs\n end for law\nend harness\n"
|
|
2360
|
+
}
|
|
2361
|
+
}
|
|
2362
|
+
},
|
|
2363
|
+
{
|
|
2364
|
+
"id": "repair",
|
|
2365
|
+
"title": "Deliver the ordered queue",
|
|
2366
|
+
"story": [
|
|
2367
|
+
"The starter returns the ranks unchanged. It retains every request but leaves an out-of-order queue out of order. Run it to see the remaining failure.",
|
|
2368
|
+
"Implement a sort that satisfies both requirements, then rerun checks with All checks. Keep the two rank-1 requests in the named example.",
|
|
2369
|
+
"As your own challenge, write a case with three requests sharing one rank and another request at a different rank. Predict the result and check both counts and order. You will have tests that distinguish equal priority from duplicate identity."
|
|
2370
|
+
],
|
|
2371
|
+
"focus": "Solution",
|
|
2372
|
+
"project": "exercises/weak-properties/04",
|
|
2373
|
+
"run": {
|
|
2374
|
+
"mode": "all",
|
|
2375
|
+
"expect": "failed",
|
|
2376
|
+
"sampled": "failed",
|
|
2377
|
+
"seed": 424242
|
|
2378
|
+
},
|
|
2379
|
+
"action": "Observe the ordering failure, implement a correct queue sort and add your own repeated-priority example.",
|
|
2380
|
+
"reason": "The output must serve the library’s purpose: correct order with every request retained.",
|
|
2381
|
+
"expect": "The supplied code compiles, then the selected checks fail. A compiler error is a different problem; inspect diagnostics if execution did not start.",
|
|
2382
|
+
"recovery": "Reset this step restores its supplied files and seed. After an edit, use the actual result to judge your version; the story’s prediction describes the supplied files.",
|
|
2383
|
+
"challenge": true,
|
|
2384
|
+
"editor": "Tests",
|
|
2385
|
+
"syntax": "The property joins the ordering helper and sameItems with and. Returning the original list satisfies preservation but can fail ordering.",
|
|
2386
|
+
"harnessNotes": [
|
|
2387
|
+
"number draws integers from -20 through 20. The short-list strategy draws a, b and c from number using nested bind expressions: each bind makes its drawn value available inside the following expression.",
|
|
2388
|
+
"one of chooses between [], [a], [a, b] and [a, b, c]. These are lists of zero through three items; repeated values are possible. This recipe does not generate arbitrary-length lists. Shrinking can try smaller choices and smaller elements, keeping only candidates that still fail.",
|
|
2389
|
+
"The binding for “sorting orders values and keeps every occurrence” selects the claim in Laws; use lists for xs supplies its list input xs. The implementation returns a result, and the law checks it. The generator does not provide the expected answer."
|
|
2390
|
+
],
|
|
2391
|
+
"projects": {
|
|
2392
|
+
"fsharp": {
|
|
2393
|
+
"Solution.fs": "module Solution\n\nlet sort (xs: int list) : int list = xs\n",
|
|
2394
|
+
"Tests.lawspec": "-- ref:DEC-learn-tests-in-lawspec\nunit learn.sorting\nsort :: List Int32 -> List Int32\n\nfunction \"|is in ascending order| (xs :: List Int32) -> Bool is\n first matching case of xs :\n when Nil then true\n when Cons h t then\n (first matching case of t :\n when Nil then true\n when Cons next rest then h <= next and \"|is in ascending order| t\n end case)\n end case\nend function\n\nlaw \"|an empty input stays empty| is\n definition:\n sort [] = []\n end definition\nend law\n\nlaw \"|requests with equal priority both stay| is\n definition:\n sort [3, 1, 1] = [1, 1, 3]\n end definition\nend law\n\nlaw \"|sorting orders values and keeps every occurrence| is\n definition:\n for all (xs :: List Int32) =>\n \"|is in ascending order| (sort xs) = true and sameItems (sort xs) xs\n end for all\n end definition\nend law\n\nend unit\n",
|
|
2395
|
+
"Harness.lawspec": "harness learn.sorting.testing for learn.sorting is\n strategy number :: (n :: Int32 where n >= -20 and n <= 20) is any end strategy\n\n -- Draw up to three items constructively; shrinking follows these choices.\n strategy lists :: List Int32 is\n bind a :: Int32 from number in\n bind b :: Int32 from number in\n bind c :: Int32 from number in\n one of [], [a], [a, b], [a, b, c]\n end bind end bind end bind\n end strategy\n\n for law \"|sorting orders values and keeps every occurrence|\n use lists for xs\n end for law\nend harness\n"
|
|
2396
|
+
},
|
|
2397
|
+
"typescript": {
|
|
2398
|
+
"Solution.ts": "export function sort(xs: number[]): number[]\n{\n return xs;\n}\n",
|
|
2399
|
+
"Tests.lawspec": "-- ref:DEC-learn-tests-in-lawspec\nunit learn.sorting\nsort :: List Int32 -> List Int32\n\nfunction \"|is in ascending order| (xs :: List Int32) -> Bool is\n first matching case of xs :\n when Nil then true\n when Cons h t then\n (first matching case of t :\n when Nil then true\n when Cons next rest then h <= next and \"|is in ascending order| t\n end case)\n end case\nend function\n\nlaw \"|an empty input stays empty| is\n definition:\n sort [] = []\n end definition\nend law\n\nlaw \"|requests with equal priority both stay| is\n definition:\n sort [3, 1, 1] = [1, 1, 3]\n end definition\nend law\n\nlaw \"|sorting orders values and keeps every occurrence| is\n definition:\n for all (xs :: List Int32) =>\n \"|is in ascending order| (sort xs) = true and sameItems (sort xs) xs\n end for all\n end definition\nend law\n\nend unit\n",
|
|
2400
|
+
"Harness.lawspec": "harness learn.sorting.testing for learn.sorting is\n strategy number :: (n :: Int32 where n >= -20 and n <= 20) is any end strategy\n\n -- Draw up to three items constructively; shrinking follows these choices.\n strategy lists :: List Int32 is\n bind a :: Int32 from number in\n bind b :: Int32 from number in\n bind c :: Int32 from number in\n one of [], [a], [a, b], [a, b, c]\n end bind end bind end bind\n end strategy\n\n for law \"|sorting orders values and keeps every occurrence|\n use lists for xs\n end for law\nend harness\n"
|
|
2401
|
+
},
|
|
2402
|
+
"javascript": {
|
|
2403
|
+
"Solution.js": "export function sort(xs)\n{\n return xs;\n}\n",
|
|
2404
|
+
"Tests.lawspec": "-- ref:DEC-learn-tests-in-lawspec\nunit learn.sorting\nsort :: List Int32 -> List Int32\n\nfunction \"|is in ascending order| (xs :: List Int32) -> Bool is\n first matching case of xs :\n when Nil then true\n when Cons h t then\n (first matching case of t :\n when Nil then true\n when Cons next rest then h <= next and \"|is in ascending order| t\n end case)\n end case\nend function\n\nlaw \"|an empty input stays empty| is\n definition:\n sort [] = []\n end definition\nend law\n\nlaw \"|requests with equal priority both stay| is\n definition:\n sort [3, 1, 1] = [1, 1, 3]\n end definition\nend law\n\nlaw \"|sorting orders values and keeps every occurrence| is\n definition:\n for all (xs :: List Int32) =>\n \"|is in ascending order| (sort xs) = true and sameItems (sort xs) xs\n end for all\n end definition\nend law\n\nend unit\n",
|
|
2405
|
+
"Harness.lawspec": "harness learn.sorting.testing for learn.sorting is\n strategy number :: (n :: Int32 where n >= -20 and n <= 20) is any end strategy\n\n -- Draw up to three items constructively; shrinking follows these choices.\n strategy lists :: List Int32 is\n bind a :: Int32 from number in\n bind b :: Int32 from number in\n bind c :: Int32 from number in\n one of [], [a], [a, b], [a, b, c]\n end bind end bind end bind\n end strategy\n\n for law \"|sorting orders values and keeps every occurrence|\n use lists for xs\n end for law\nend harness\n"
|
|
2406
|
+
}
|
|
2407
|
+
},
|
|
2408
|
+
"sources": {
|
|
2409
|
+
"fsharp": {
|
|
2410
|
+
"Tests.lawspec": "exercises/weak-properties/04/Tests.lawspec",
|
|
2411
|
+
"Harness.lawspec": "exercises/weak-properties/04/Harness.lawspec",
|
|
2412
|
+
"Solution.fs": "exercises/weak-properties/04/fsharp/Solution.fs"
|
|
2413
|
+
},
|
|
2414
|
+
"typescript": {
|
|
2415
|
+
"Tests.lawspec": "exercises/weak-properties/04/Tests.lawspec",
|
|
2416
|
+
"Harness.lawspec": "exercises/weak-properties/04/Harness.lawspec",
|
|
2417
|
+
"Solution.ts": "exercises/weak-properties/04/typescript/Solution.ts"
|
|
2418
|
+
},
|
|
2419
|
+
"javascript": {
|
|
2420
|
+
"Tests.lawspec": "exercises/weak-properties/04/Tests.lawspec",
|
|
2421
|
+
"Harness.lawspec": "exercises/weak-properties/04/Harness.lawspec",
|
|
2422
|
+
"Solution.js": "exercises/weak-properties/04/javascript/Solution.js"
|
|
2423
|
+
}
|
|
2424
|
+
},
|
|
2425
|
+
"previousProjects": {
|
|
2426
|
+
"fsharp": {
|
|
2427
|
+
"Solution.fs": "module Solution\n\nlet sort (xs: int list) : int list = xs\n",
|
|
2428
|
+
"Tests.lawspec": "-- ref:DEC-learn-tests-in-lawspec\nunit learn.sorting\nsort :: List Int32 -> List Int32\n\nfunction ordered (xs :: List Int32) -> Bool is\n first matching case of xs :\n when Nil then true\n when Cons h t then\n (first matching case of t :\n when Nil then true\n when Cons next rest then h <= next and ordered t\n end case)\n end case\nend function\n\nlaw emptyInput is\n definition:\n sort [] = []\n end definition\nend law\n\nlaw duplicateRequests is\n definition:\n sort [3, 1, 1] = [1, 1, 3]\n end definition\nend law\n\nlaw sortingRule is\n definition:\n for all (xs :: List Int32) => ordered (sort xs) = true and sameItems (sort\n xs) xs end for all\n end definition\nend law\n\nend unit\n",
|
|
2429
|
+
"Harness.lawspec": "harness learn.sorting.testing for learn.sorting is\n strategy number :: (n :: Int32 where n >= -20 and n <= 20) is any end strategy\n\n -- Draw up to three items constructively; shrinking follows these choices.\n strategy lists :: List Int32 is\n bind a :: Int32 from number in\n bind b :: Int32 from number in\n bind c :: Int32 from number in\n one of [], [a], [a, b], [a, b, c]\n end bind end bind end bind\n end strategy\n\n for law sortingRule\n use lists for xs\n end for law\nend harness\n"
|
|
2430
|
+
},
|
|
2431
|
+
"typescript": {
|
|
2432
|
+
"Solution.ts": "export function sort(xs: number[]): number[]\n{\n return xs;\n}\n",
|
|
2433
|
+
"Tests.lawspec": "-- ref:DEC-learn-tests-in-lawspec\nunit learn.sorting\nsort :: List Int32 -> List Int32\n\nfunction ordered (xs :: List Int32) -> Bool is\n first matching case of xs :\n when Nil then true\n when Cons h t then\n (first matching case of t :\n when Nil then true\n when Cons next rest then h <= next and ordered t\n end case)\n end case\nend function\n\nlaw emptyInput is\n definition:\n sort [] = []\n end definition\nend law\n\nlaw duplicateRequests is\n definition:\n sort [3, 1, 1] = [1, 1, 3]\n end definition\nend law\n\nlaw sortingRule is\n definition:\n for all (xs :: List Int32) => ordered (sort xs) = true and sameItems (sort\n xs) xs end for all\n end definition\nend law\n\nend unit\n",
|
|
2434
|
+
"Harness.lawspec": "harness learn.sorting.testing for learn.sorting is\n strategy number :: (n :: Int32 where n >= -20 and n <= 20) is any end strategy\n\n -- Draw up to three items constructively; shrinking follows these choices.\n strategy lists :: List Int32 is\n bind a :: Int32 from number in\n bind b :: Int32 from number in\n bind c :: Int32 from number in\n one of [], [a], [a, b], [a, b, c]\n end bind end bind end bind\n end strategy\n\n for law sortingRule\n use lists for xs\n end for law\nend harness\n"
|
|
2435
|
+
},
|
|
2436
|
+
"javascript": {
|
|
2437
|
+
"Solution.js": "export function sort(xs)\n{\n return xs;\n}\n",
|
|
2438
|
+
"Tests.lawspec": "-- ref:DEC-learn-tests-in-lawspec\nunit learn.sorting\nsort :: List Int32 -> List Int32\n\nfunction ordered (xs :: List Int32) -> Bool is\n first matching case of xs :\n when Nil then true\n when Cons h t then\n (first matching case of t :\n when Nil then true\n when Cons next rest then h <= next and ordered t\n end case)\n end case\nend function\n\nlaw emptyInput is\n definition:\n sort [] = []\n end definition\nend law\n\nlaw duplicateRequests is\n definition:\n sort [3, 1, 1] = [1, 1, 3]\n end definition\nend law\n\nlaw sortingRule is\n definition:\n for all (xs :: List Int32) => ordered (sort xs) = true and sameItems (sort\n xs) xs end for all\n end definition\nend law\n\nend unit\n",
|
|
2439
|
+
"Harness.lawspec": "harness learn.sorting.testing for learn.sorting is\n strategy number :: (n :: Int32 where n >= -20 and n <= 20) is any end strategy\n\n -- Draw up to three items constructively; shrinking follows these choices.\n strategy lists :: List Int32 is\n bind a :: Int32 from number in\n bind b :: Int32 from number in\n bind c :: Int32 from number in\n one of [], [a], [a, b], [a, b, c]\n end bind end bind end bind\n end strategy\n\n for law sortingRule\n use lists for xs\n end for law\nend harness\n"
|
|
2440
|
+
}
|
|
2441
|
+
}
|
|
2442
|
+
}
|
|
2443
|
+
],
|
|
2444
|
+
"solutionProject": "exercises/weak-properties/solution",
|
|
2445
|
+
"coverage": {
|
|
2446
|
+
"browserExecution": [
|
|
2447
|
+
"fsharp",
|
|
2448
|
+
"typescript",
|
|
2449
|
+
"javascript"
|
|
2450
|
+
],
|
|
2451
|
+
"definitionChecking": true,
|
|
2452
|
+
"nativeExecution": "deferred",
|
|
2453
|
+
"apiCollectionCredit": "deferred: this story is not a complete public API collection"
|
|
2454
|
+
},
|
|
2455
|
+
"implementationSyntax": {
|
|
2456
|
+
"fsharp": "In F#, List.sort orders ranks; List.distinct removes equal values, which loses separate requests at the same rank.",
|
|
2457
|
+
"typescript": "In TypeScript, number[] holds the ranks. A numeric comparator orders them; new Set removes equal values, losing requests at the same rank.",
|
|
2458
|
+
"javascript": "In JavaScript, the array holds the ranks. A numeric comparator orders them; new Set removes equal values, losing requests at the same rank."
|
|
2459
|
+
},
|
|
2460
|
+
"naming": "Use English phrase names for readable claims and descriptive LawSpec helpers. Keep short code names such as add, sort, xs and numbers when they make calls and recipes easier to follow. A phrase starts with \"| and ends with |, without a closing quote. A law label identifies the claim; renaming it does not change what the definition checks. The compiler generates target-appropriate names.",
|
|
2461
|
+
"projects": {
|
|
2462
|
+
"fsharp": {
|
|
2463
|
+
"Solution.fs": "module Solution\n\nlet sort (xs: int list) : int list = []\n",
|
|
2464
|
+
"Tests.lawspec": "-- ref:DEC-learn-tests-in-lawspec\nunit learn.sorting\nsort :: List Int32 -> List Int32\n\nfunction \"|is in ascending order| (xs :: List Int32) -> Bool is\n first matching case of xs :\n when Nil then true\n when Cons h t then\n (first matching case of t :\n when Nil then true\n when Cons next rest then h <= next and \"|is in ascending order| t\n end case)\n end case\nend function\n\nlaw \"|an empty input stays empty| is\n definition:\n sort [] = []\n end definition\nend law\n\nlaw \"|the result is in ascending order| is\n definition:\n for all (xs :: List Int32) =>\n \"|is in ascending order| (sort xs) = true\n end for all\n end definition\nend law\n\nend unit\n",
|
|
2465
|
+
"Harness.lawspec": "harness learn.sorting.testing for learn.sorting is\n strategy number :: (n :: Int32 where n >= -20 and n <= 20) is any end strategy\n\n -- Draw up to three items constructively; shrinking follows these choices.\n strategy lists :: List Int32 is\n bind a :: Int32 from number in\n bind b :: Int32 from number in\n bind c :: Int32 from number in\n one of [], [a], [a, b], [a, b, c]\n end bind end bind end bind\n end strategy\n\n for law \"|the result is in ascending order|\n use lists for xs\n end for law\nend harness\n"
|
|
2466
|
+
},
|
|
2467
|
+
"typescript": {
|
|
2468
|
+
"Solution.ts": "export function sort(xs: number[]): number[]\n{\n return [];\n}\n",
|
|
2469
|
+
"Tests.lawspec": "-- ref:DEC-learn-tests-in-lawspec\nunit learn.sorting\nsort :: List Int32 -> List Int32\n\nfunction \"|is in ascending order| (xs :: List Int32) -> Bool is\n first matching case of xs :\n when Nil then true\n when Cons h t then\n (first matching case of t :\n when Nil then true\n when Cons next rest then h <= next and \"|is in ascending order| t\n end case)\n end case\nend function\n\nlaw \"|an empty input stays empty| is\n definition:\n sort [] = []\n end definition\nend law\n\nlaw \"|the result is in ascending order| is\n definition:\n for all (xs :: List Int32) =>\n \"|is in ascending order| (sort xs) = true\n end for all\n end definition\nend law\n\nend unit\n",
|
|
2470
|
+
"Harness.lawspec": "harness learn.sorting.testing for learn.sorting is\n strategy number :: (n :: Int32 where n >= -20 and n <= 20) is any end strategy\n\n -- Draw up to three items constructively; shrinking follows these choices.\n strategy lists :: List Int32 is\n bind a :: Int32 from number in\n bind b :: Int32 from number in\n bind c :: Int32 from number in\n one of [], [a], [a, b], [a, b, c]\n end bind end bind end bind\n end strategy\n\n for law \"|the result is in ascending order|\n use lists for xs\n end for law\nend harness\n"
|
|
2471
|
+
},
|
|
2472
|
+
"javascript": {
|
|
2473
|
+
"Solution.js": "export function sort(xs)\n{\n return [];\n}\n",
|
|
2474
|
+
"Tests.lawspec": "-- ref:DEC-learn-tests-in-lawspec\nunit learn.sorting\nsort :: List Int32 -> List Int32\n\nfunction \"|is in ascending order| (xs :: List Int32) -> Bool is\n first matching case of xs :\n when Nil then true\n when Cons h t then\n (first matching case of t :\n when Nil then true\n when Cons next rest then h <= next and \"|is in ascending order| t\n end case)\n end case\nend function\n\nlaw \"|an empty input stays empty| is\n definition:\n sort [] = []\n end definition\nend law\n\nlaw \"|the result is in ascending order| is\n definition:\n for all (xs :: List Int32) =>\n \"|is in ascending order| (sort xs) = true\n end for all\n end definition\nend law\n\nend unit\n",
|
|
2475
|
+
"Harness.lawspec": "harness learn.sorting.testing for learn.sorting is\n strategy number :: (n :: Int32 where n >= -20 and n <= 20) is any end strategy\n\n -- Draw up to three items constructively; shrinking follows these choices.\n strategy lists :: List Int32 is\n bind a :: Int32 from number in\n bind b :: Int32 from number in\n bind c :: Int32 from number in\n one of [], [a], [a, b], [a, b, c]\n end bind end bind end bind\n end strategy\n\n for law \"|the result is in ascending order|\n use lists for xs\n end for law\nend harness\n"
|
|
2476
|
+
}
|
|
2477
|
+
},
|
|
2478
|
+
"solutions": {
|
|
2479
|
+
"fsharp": {
|
|
2480
|
+
"Solution.fs": "module Solution\n\nlet sort (xs: int list) : int list = List.sort xs\n",
|
|
2481
|
+
"Tests.lawspec": "-- ref:DEC-learn-tests-in-lawspec\nunit learn.sorting\nsort :: List Int32 -> List Int32\n\nfunction \"|is in ascending order| (xs :: List Int32) -> Bool is\n first matching case of xs :\n when Nil then true\n when Cons h t then\n (first matching case of t :\n when Nil then true\n when Cons next rest then h <= next and \"|is in ascending order| t\n end case)\n end case\nend function\n\nlaw \"|an empty input stays empty| is\n definition:\n sort [] = []\n end definition\nend law\n\nlaw \"|requests with equal priority both stay| is\n definition:\n sort [3, 1, 1] = [1, 1, 3]\n end definition\nend law\n\nlaw \"|sorting orders values and keeps every occurrence| is\n definition:\n for all (xs :: List Int32) =>\n \"|is in ascending order| (sort xs) = true and sameItems (sort xs) xs\n end for all\n end definition\nend law\n\nend unit\n",
|
|
2482
|
+
"Harness.lawspec": "harness learn.sorting.testing for learn.sorting is\n strategy number :: (n :: Int32 where n >= -20 and n <= 20) is any end strategy\n\n -- Draw up to three items constructively; shrinking follows these choices.\n strategy lists :: List Int32 is\n bind a :: Int32 from number in\n bind b :: Int32 from number in\n bind c :: Int32 from number in\n one of [], [a], [a, b], [a, b, c]\n end bind end bind end bind\n end strategy\n\n for law \"|sorting orders values and keeps every occurrence|\n use lists for xs\n end for law\nend harness\n"
|
|
2483
|
+
},
|
|
2484
|
+
"typescript": {
|
|
2485
|
+
"Solution.ts": "export function sort(xs: number[]): number[]\n{\n return [...xs].sort((a, b) => a - b);\n}\n",
|
|
2486
|
+
"Tests.lawspec": "-- ref:DEC-learn-tests-in-lawspec\nunit learn.sorting\nsort :: List Int32 -> List Int32\n\nfunction \"|is in ascending order| (xs :: List Int32) -> Bool is\n first matching case of xs :\n when Nil then true\n when Cons h t then\n (first matching case of t :\n when Nil then true\n when Cons next rest then h <= next and \"|is in ascending order| t\n end case)\n end case\nend function\n\nlaw \"|an empty input stays empty| is\n definition:\n sort [] = []\n end definition\nend law\n\nlaw \"|requests with equal priority both stay| is\n definition:\n sort [3, 1, 1] = [1, 1, 3]\n end definition\nend law\n\nlaw \"|sorting orders values and keeps every occurrence| is\n definition:\n for all (xs :: List Int32) =>\n \"|is in ascending order| (sort xs) = true and sameItems (sort xs) xs\n end for all\n end definition\nend law\n\nend unit\n",
|
|
2487
|
+
"Harness.lawspec": "harness learn.sorting.testing for learn.sorting is\n strategy number :: (n :: Int32 where n >= -20 and n <= 20) is any end strategy\n\n -- Draw up to three items constructively; shrinking follows these choices.\n strategy lists :: List Int32 is\n bind a :: Int32 from number in\n bind b :: Int32 from number in\n bind c :: Int32 from number in\n one of [], [a], [a, b], [a, b, c]\n end bind end bind end bind\n end strategy\n\n for law \"|sorting orders values and keeps every occurrence|\n use lists for xs\n end for law\nend harness\n"
|
|
2488
|
+
},
|
|
2489
|
+
"javascript": {
|
|
2490
|
+
"Solution.js": "export function sort(xs)\n{\n return [...xs].sort((a, b) => a - b);\n}\n",
|
|
2491
|
+
"Tests.lawspec": "-- ref:DEC-learn-tests-in-lawspec\nunit learn.sorting\nsort :: List Int32 -> List Int32\n\nfunction \"|is in ascending order| (xs :: List Int32) -> Bool is\n first matching case of xs :\n when Nil then true\n when Cons h t then\n (first matching case of t :\n when Nil then true\n when Cons next rest then h <= next and \"|is in ascending order| t\n end case)\n end case\nend function\n\nlaw \"|an empty input stays empty| is\n definition:\n sort [] = []\n end definition\nend law\n\nlaw \"|requests with equal priority both stay| is\n definition:\n sort [3, 1, 1] = [1, 1, 3]\n end definition\nend law\n\nlaw \"|sorting orders values and keeps every occurrence| is\n definition:\n for all (xs :: List Int32) =>\n \"|is in ascending order| (sort xs) = true and sameItems (sort xs) xs\n end for all\n end definition\nend law\n\nend unit\n",
|
|
2492
|
+
"Harness.lawspec": "harness learn.sorting.testing for learn.sorting is\n strategy number :: (n :: Int32 where n >= -20 and n <= 20) is any end strategy\n\n -- Draw up to three items constructively; shrinking follows these choices.\n strategy lists :: List Int32 is\n bind a :: Int32 from number in\n bind b :: Int32 from number in\n bind c :: Int32 from number in\n one of [], [a], [a, b], [a, b, c]\n end bind end bind end bind\n end strategy\n\n for law \"|sorting orders values and keeps every occurrence|\n use lists for xs\n end for law\nend harness\n"
|
|
2493
|
+
}
|
|
2494
|
+
},
|
|
2495
|
+
"solutionSources": {
|
|
2496
|
+
"fsharp": {
|
|
2497
|
+
"Tests.lawspec": "exercises/weak-properties/solution/Tests.lawspec",
|
|
2498
|
+
"Harness.lawspec": "exercises/weak-properties/solution/Harness.lawspec",
|
|
2499
|
+
"Solution.fs": "exercises/weak-properties/solution/fsharp/Solution.fs"
|
|
2500
|
+
},
|
|
2501
|
+
"typescript": {
|
|
2502
|
+
"Tests.lawspec": "exercises/weak-properties/solution/Tests.lawspec",
|
|
2503
|
+
"Harness.lawspec": "exercises/weak-properties/solution/Harness.lawspec",
|
|
2504
|
+
"Solution.ts": "exercises/weak-properties/solution/typescript/Solution.ts"
|
|
2505
|
+
},
|
|
2506
|
+
"javascript": {
|
|
2507
|
+
"Tests.lawspec": "exercises/weak-properties/solution/Tests.lawspec",
|
|
2508
|
+
"Harness.lawspec": "exercises/weak-properties/solution/Harness.lawspec",
|
|
2509
|
+
"Solution.js": "exercises/weak-properties/solution/javascript/Solution.js"
|
|
2510
|
+
}
|
|
2511
|
+
}
|
|
2512
|
+
},
|
|
2513
|
+
{
|
|
2514
|
+
"id": "shrinking",
|
|
2515
|
+
"title": "Practice: keep the freezing temperature",
|
|
2516
|
+
"section": "Apply the ideas",
|
|
2517
|
+
"vision": "Find and repair a temperature summary that mistakes a real 0 °C reading for missing data.",
|
|
2518
|
+
"slogan": "Zero is a reading.",
|
|
2519
|
+
"symbol": "0 °C is a measurement",
|
|
2520
|
+
"explanation": "Laws and generation strategies are authored in LawSpec. Only the implementation changes language.",
|
|
2521
|
+
"news": "Input generation must include meaningful boundary values such as a real zero reading.",
|
|
2522
|
+
"contributions": "A distinct-temperature summary, an input strategy that includes freezing and negative values, the actual shrunk failure [0], seed/path replay and a saved freezing regression. The repaired function retains zero while removing repeats; evidence is scoped to these examples and short generated lists.",
|
|
2523
|
+
"star": {
|
|
2524
|
+
"salient": "Input generation must include meaningful boundary values such as a real zero reading.",
|
|
2525
|
+
"slogan": "Zero is a reading.",
|
|
2526
|
+
"symbol": "0 °C is a measurement",
|
|
2527
|
+
"surprise": "The summary passes every positive sample while silently deleting the freezing temperature.",
|
|
2528
|
+
"story": "A weather station needs a list of distinct temperatures it recorded. Positive samples hide a zero-removal bug; a wider recipe finds it, shrinking isolates [0], and a saved example protects the repair."
|
|
2529
|
+
},
|
|
2530
|
+
"attribution": [
|
|
2531
|
+
{
|
|
2532
|
+
"title": "Scott Wlaschin — Understanding FsCheck",
|
|
2533
|
+
"url": "https://fsharpforfunandprofit.com/posts/property-based-testing-1/",
|
|
2534
|
+
"use": "Original application exercise using the generation/shrinking ideas after the threshold example."
|
|
2535
|
+
}
|
|
2536
|
+
],
|
|
2537
|
+
"hints": [
|
|
2538
|
+
"A list containing only 0 records one real temperature. Should its summary be empty?",
|
|
2539
|
+
"Trace the zero-removal operation separately from removing duplicates. Which one violates the summary’s purpose?",
|
|
2540
|
+
"Keep the distinct-value operation and remove the filter that discards zero. Load solution shows the complete repair."
|
|
2541
|
+
],
|
|
2542
|
+
"stages": [
|
|
2543
|
+
{
|
|
2544
|
+
"id": "positive",
|
|
2545
|
+
"title": "Which temperatures did the station record?",
|
|
2546
|
+
"story": [
|
|
2547
|
+
"A weather station records temperatures as whole degrees Celsius. We want a summary of which temperatures occurred, with one copy of each value. The summary’s order does not matter. Repeated readings of 2 °C should produce one 2; a reading of 0 °C must still appear. Negative temperatures are valid too. You will use a small generated failure to locate a mistake and keep it as a regression.",
|
|
2548
|
+
"This differs from the library queue: equal ranks represented separate requests there. Here we deliberately summarize distinct values rather than preserve how many times each temperature occurred. The original readings are the input; this function returns a summary.",
|
|
2549
|
+
"unique in Solution first removes zeros, then removes duplicate values. The first operation treats 0 as if it meant missing data, but our integer list has no missing-data marker. Zero means a measured 0 °C.",
|
|
2550
|
+
"Harness currently generates only temperatures from 1 through 20. Run the sampled property. It passes because every generated value avoids the faulty zero filter. Follow the same function on a list containing only 0: what should the summary contain, and what does it return? Other check modes can expose zero sooner; this step isolates the positive-only recipe.",
|
|
2551
|
+
"Read the claim “the summary keeps each recorded temperature once”. Once means one occurrence of each different value. The property compares against the distinct input values; it does not require a particular output order."
|
|
2552
|
+
],
|
|
2553
|
+
"focus": "Solution",
|
|
2554
|
+
"project": "exercises/shrinking/01",
|
|
2555
|
+
"run": {
|
|
2556
|
+
"mode": "sample",
|
|
2557
|
+
"expect": "passed",
|
|
2558
|
+
"sampled": "passed",
|
|
2559
|
+
"seed": 424242
|
|
2560
|
+
},
|
|
2561
|
+
"action": "Run the positive-only sample. Then trace unique on a single 0 °C reading and compare the intended summary with the actual result.",
|
|
2562
|
+
"reason": "Zero is a reading. A generator that only makes positive temperatures cannot reveal its loss.",
|
|
2563
|
+
"expect": "The supplied code compiles and the selected checks pass. Read which checks actually ran before interpreting this result.",
|
|
2564
|
+
"recovery": "Reset this step restores its supplied files and seed. After an edit, use the actual result to judge your version; the story’s prediction describes the supplied files.",
|
|
2565
|
+
"editor": "Tests",
|
|
2566
|
+
"syntax": "unique takes a list of integers and returns a list. sameItems compares its output with toList (setOf xs): one occurrence of each input value, rather than the original occurrence counts.",
|
|
2567
|
+
"harnessNotes": [
|
|
2568
|
+
"number draws integers from 1 through 20. The short-list strategy draws a, b and c from number using nested bind expressions: each bind makes its drawn value available inside the following expression.",
|
|
2569
|
+
"one of chooses between [], [a], [a, b] and [a, b, c]. These are lists of zero through three items; repeated values are possible. This recipe does not generate arbitrary-length lists. Shrinking can try smaller choices and smaller elements, keeping only candidates that still fail.",
|
|
2570
|
+
"The binding for “the summary keeps each recorded temperature once” selects the claim in Laws; use lists for xs supplies its list input xs. The implementation returns a result, and the law checks it. The generator does not provide the expected answer.",
|
|
2571
|
+
"Every drawn temperature is positive, so this recipe cannot reveal the bug that drops the 0 °C reading. The next step widens number while retaining the property and implementation."
|
|
2572
|
+
],
|
|
2573
|
+
"symbol": "0 °C is a measurement",
|
|
2574
|
+
"projects": {
|
|
2575
|
+
"fsharp": {
|
|
2576
|
+
"Solution.fs": "module Solution\n\nlet unique (xs: int list) : int list =\n xs |> List.filter (fun x -> x <> 0) |> List.distinct\n",
|
|
2577
|
+
"Tests.lawspec": "-- ref:DEC-learn-tests-in-lawspec\nunit learn.unique\nunique :: List Int32 -> List Int32\n\nlaw \"|repeated readings appear once| is\n definition:\n sameItems (unique [2, 2, 3]) [2, 3]\n end definition\nend law\n\nlaw \"|the summary keeps each recorded temperature once| is\n definition:\n for all (xs :: List Int32) =>\n sameItems (unique xs) (toList (setOf xs))\n end for all\n end definition\nend law\n\nend unit\n",
|
|
2578
|
+
"Harness.lawspec": "harness learn.unique.testing for learn.unique is\n strategy number :: (n :: Int32 where n >= 1 and n <= 20) is any end strategy\n\n -- Draw up to three items constructively; shrinking follows these choices.\n strategy lists :: List Int32 is\n bind a :: Int32 from number in\n bind b :: Int32 from number in\n bind c :: Int32 from number in\n one of [], [a], [a, b], [a, b, c]\n end bind end bind end bind\n end strategy\n\n for law \"|the summary keeps each recorded temperature once|\n use lists for xs\n end for law\nend harness\n"
|
|
2579
|
+
},
|
|
2580
|
+
"typescript": {
|
|
2581
|
+
"Solution.ts": "export function unique(xs: number[]): number[]\n{\n return [...new Set(xs.filter(x => x !== 0))];\n}\n",
|
|
2582
|
+
"Tests.lawspec": "-- ref:DEC-learn-tests-in-lawspec\nunit learn.unique\nunique :: List Int32 -> List Int32\n\nlaw \"|repeated readings appear once| is\n definition:\n sameItems (unique [2, 2, 3]) [2, 3]\n end definition\nend law\n\nlaw \"|the summary keeps each recorded temperature once| is\n definition:\n for all (xs :: List Int32) =>\n sameItems (unique xs) (toList (setOf xs))\n end for all\n end definition\nend law\n\nend unit\n",
|
|
2583
|
+
"Harness.lawspec": "harness learn.unique.testing for learn.unique is\n strategy number :: (n :: Int32 where n >= 1 and n <= 20) is any end strategy\n\n -- Draw up to three items constructively; shrinking follows these choices.\n strategy lists :: List Int32 is\n bind a :: Int32 from number in\n bind b :: Int32 from number in\n bind c :: Int32 from number in\n one of [], [a], [a, b], [a, b, c]\n end bind end bind end bind\n end strategy\n\n for law \"|the summary keeps each recorded temperature once|\n use lists for xs\n end for law\nend harness\n"
|
|
2584
|
+
},
|
|
2585
|
+
"javascript": {
|
|
2586
|
+
"Solution.js": "export function unique(xs)\n{\n return [...new Set(xs.filter(x => x !== 0))];\n}\n",
|
|
2587
|
+
"Tests.lawspec": "-- ref:DEC-learn-tests-in-lawspec\nunit learn.unique\nunique :: List Int32 -> List Int32\n\nlaw \"|repeated readings appear once| is\n definition:\n sameItems (unique [2, 2, 3]) [2, 3]\n end definition\nend law\n\nlaw \"|the summary keeps each recorded temperature once| is\n definition:\n for all (xs :: List Int32) =>\n sameItems (unique xs) (toList (setOf xs))\n end for all\n end definition\nend law\n\nend unit\n",
|
|
2588
|
+
"Harness.lawspec": "harness learn.unique.testing for learn.unique is\n strategy number :: (n :: Int32 where n >= 1 and n <= 20) is any end strategy\n\n -- Draw up to three items constructively; shrinking follows these choices.\n strategy lists :: List Int32 is\n bind a :: Int32 from number in\n bind b :: Int32 from number in\n bind c :: Int32 from number in\n one of [], [a], [a, b], [a, b, c]\n end bind end bind end bind\n end strategy\n\n for law \"|the summary keeps each recorded temperature once|\n use lists for xs\n end for law\nend harness\n"
|
|
2589
|
+
}
|
|
2590
|
+
},
|
|
2591
|
+
"sources": {
|
|
2592
|
+
"fsharp": {
|
|
2593
|
+
"Tests.lawspec": "exercises/shrinking/01/Tests.lawspec",
|
|
2594
|
+
"Harness.lawspec": "exercises/shrinking/01/Harness.lawspec",
|
|
2595
|
+
"Solution.fs": "exercises/shrinking/01/fsharp/Solution.fs"
|
|
2596
|
+
},
|
|
2597
|
+
"typescript": {
|
|
2598
|
+
"Tests.lawspec": "exercises/shrinking/01/Tests.lawspec",
|
|
2599
|
+
"Harness.lawspec": "exercises/shrinking/01/Harness.lawspec",
|
|
2600
|
+
"Solution.ts": "exercises/shrinking/01/typescript/Solution.ts"
|
|
2601
|
+
},
|
|
2602
|
+
"javascript": {
|
|
2603
|
+
"Tests.lawspec": "exercises/shrinking/01/Tests.lawspec",
|
|
2604
|
+
"Harness.lawspec": "exercises/shrinking/01/Harness.lawspec",
|
|
2605
|
+
"Solution.js": "exercises/shrinking/01/javascript/Solution.js"
|
|
2606
|
+
}
|
|
2607
|
+
},
|
|
2608
|
+
"previousProjects": {
|
|
2609
|
+
"fsharp": {
|
|
2610
|
+
"Solution.fs": "module Solution\n\nlet unique (xs: int list) : int list =\n xs |> List.filter (fun x -> x <> 0) |> List.distinct\n",
|
|
2611
|
+
"Tests.lawspec": "-- ref:DEC-learn-tests-in-lawspec\nunit learn.unique\nunique :: List Int32 -> List Int32\n\nlaw repeatedReading is\n definition:\n sameItems (unique [2, 2, 3]) [2, 3]\n end definition\nend law\n\nlaw uniqueRule is\n definition:\n for all (xs :: List Int32) => sameItems (unique xs) (toList (setOf xs))\n end for all\n end definition\nend law\n\nend unit\n",
|
|
2612
|
+
"Harness.lawspec": "harness learn.unique.testing for learn.unique is\n strategy number :: (n :: Int32 where n >= 1 and n <= 20) is any end strategy\n\n -- Draw up to three items constructively; shrinking follows these choices.\n strategy lists :: List Int32 is\n bind a :: Int32 from number in\n bind b :: Int32 from number in\n bind c :: Int32 from number in\n one of [], [a], [a, b], [a, b, c]\n end bind end bind end bind\n end strategy\n\n for law uniqueRule\n use lists for xs\n end for law\nend harness\n"
|
|
2613
|
+
},
|
|
2614
|
+
"typescript": {
|
|
2615
|
+
"Solution.ts": "export function unique(xs: number[]): number[]\n{\n return [...new Set(xs.filter(x => x !== 0))];\n}\n",
|
|
2616
|
+
"Tests.lawspec": "-- ref:DEC-learn-tests-in-lawspec\nunit learn.unique\nunique :: List Int32 -> List Int32\n\nlaw repeatedReading is\n definition:\n sameItems (unique [2, 2, 3]) [2, 3]\n end definition\nend law\n\nlaw uniqueRule is\n definition:\n for all (xs :: List Int32) => sameItems (unique xs) (toList (setOf xs))\n end for all\n end definition\nend law\n\nend unit\n",
|
|
2617
|
+
"Harness.lawspec": "harness learn.unique.testing for learn.unique is\n strategy number :: (n :: Int32 where n >= 1 and n <= 20) is any end strategy\n\n -- Draw up to three items constructively; shrinking follows these choices.\n strategy lists :: List Int32 is\n bind a :: Int32 from number in\n bind b :: Int32 from number in\n bind c :: Int32 from number in\n one of [], [a], [a, b], [a, b, c]\n end bind end bind end bind\n end strategy\n\n for law uniqueRule\n use lists for xs\n end for law\nend harness\n"
|
|
2618
|
+
},
|
|
2619
|
+
"javascript": {
|
|
2620
|
+
"Solution.js": "export function unique(xs)\n{\n return [...new Set(xs.filter(x => x !== 0))];\n}\n",
|
|
2621
|
+
"Tests.lawspec": "-- ref:DEC-learn-tests-in-lawspec\nunit learn.unique\nunique :: List Int32 -> List Int32\n\nlaw repeatedReading is\n definition:\n sameItems (unique [2, 2, 3]) [2, 3]\n end definition\nend law\n\nlaw uniqueRule is\n definition:\n for all (xs :: List Int32) => sameItems (unique xs) (toList (setOf xs))\n end for all\n end definition\nend law\n\nend unit\n",
|
|
2622
|
+
"Harness.lawspec": "harness learn.unique.testing for learn.unique is\n strategy number :: (n :: Int32 where n >= 1 and n <= 20) is any end strategy\n\n -- Draw up to three items constructively; shrinking follows these choices.\n strategy lists :: List Int32 is\n bind a :: Int32 from number in\n bind b :: Int32 from number in\n bind c :: Int32 from number in\n one of [], [a], [a, b], [a, b, c]\n end bind end bind end bind\n end strategy\n\n for law uniqueRule\n use lists for xs\n end for law\nend harness\n"
|
|
2623
|
+
}
|
|
2624
|
+
}
|
|
2625
|
+
},
|
|
2626
|
+
{
|
|
2627
|
+
"id": "widen",
|
|
2628
|
+
"title": "Let the generator reach freezing and below",
|
|
2629
|
+
"story": [
|
|
2630
|
+
"Harness now draws temperatures from -20 through 20. The list recipe still makes zero through three readings. The implementation and property are unchanged; only the possible test data widened.",
|
|
2631
|
+
"Run with seed 424242 and inspect the actual failure and shrink attempts. This run shrinks to a list containing just 0. Its expected summary contains 0, but the filter returns an empty list. No duplicates are needed to reproduce the bug.",
|
|
2632
|
+
"Use Replay failure before editing. Then use Save regression to add this observed input to Laws. Shrinking explains the failure; the saved example gives us a short way to keep checking it.",
|
|
2633
|
+
"The visible failing input comes from this run. Open How the failure was reduced to inspect the actual attempts; no fixed sequence is being presented as your run’s trace."
|
|
2634
|
+
],
|
|
2635
|
+
"focus": "Harness.lawspec",
|
|
2636
|
+
"project": "exercises/shrinking/02",
|
|
2637
|
+
"run": {
|
|
2638
|
+
"mode": "sample",
|
|
2639
|
+
"expect": "failed",
|
|
2640
|
+
"sampled": "failed",
|
|
2641
|
+
"counterexample": [
|
|
2642
|
+
[
|
|
2643
|
+
0
|
|
2644
|
+
]
|
|
2645
|
+
],
|
|
2646
|
+
"minShrinks": 1,
|
|
2647
|
+
"seed": 424242
|
|
2648
|
+
},
|
|
2649
|
+
"action": "Run the wider sample, inspect the final [0] counterexample, replay it and save it as a regression.",
|
|
2650
|
+
"reason": "The smallest surviving case isolates loss of a valid value from the separate task of removing repeats.",
|
|
2651
|
+
"expect": "The supplied code compiles, then the selected checks fail. A compiler error is a different problem; inspect diagnostics if execution did not start.",
|
|
2652
|
+
"recovery": "Reset this step restores its supplied files and seed. After an edit, use the actual result to judge your version; the story’s prediction describes the supplied files.",
|
|
2653
|
+
"regression": {
|
|
2654
|
+
"input": [
|
|
2655
|
+
0
|
|
2656
|
+
],
|
|
2657
|
+
"expected": [
|
|
2658
|
+
0
|
|
2659
|
+
]
|
|
2660
|
+
},
|
|
2661
|
+
"editor": "Tests",
|
|
2662
|
+
"syntax": "The number strategy now includes zero and negatives. bind draws values and one of builds short lists. Shrinking retries candidates against “the summary keeps each recorded temperature once”; it does not invent an expected output.",
|
|
2663
|
+
"harnessNotes": [
|
|
2664
|
+
"number draws integers from -20 through 20. The short-list strategy draws a, b and c from number using nested bind expressions: each bind makes its drawn value available inside the following expression.",
|
|
2665
|
+
"one of chooses between [], [a], [a, b] and [a, b, c]. These are lists of zero through three items; repeated values are possible. This recipe does not generate arbitrary-length lists. Shrinking can try smaller choices and smaller elements, keeping only candidates that still fail.",
|
|
2666
|
+
"The binding for “the summary keeps each recorded temperature once” selects the claim in Laws; use lists for xs supplies its list input xs. The implementation returns a result, and the law checks it. The generator does not provide the expected answer."
|
|
2667
|
+
],
|
|
2668
|
+
"projects": {
|
|
2669
|
+
"fsharp": {
|
|
2670
|
+
"Solution.fs": "module Solution\n\nlet unique (xs: int list) : int list =\n xs |> List.filter (fun x -> x <> 0) |> List.distinct\n",
|
|
2671
|
+
"Tests.lawspec": "-- ref:DEC-learn-tests-in-lawspec\nunit learn.unique\nunique :: List Int32 -> List Int32\n\nlaw \"|repeated readings appear once| is\n definition:\n sameItems (unique [2, 2, 3]) [2, 3]\n end definition\nend law\n\nlaw \"|the summary keeps each recorded temperature once| is\n definition:\n for all (xs :: List Int32) =>\n sameItems (unique xs) (toList (setOf xs))\n end for all\n end definition\nend law\n\nend unit\n",
|
|
2672
|
+
"Harness.lawspec": "harness learn.unique.testing for learn.unique is\n strategy number :: (n :: Int32 where n >= -20 and n <= 20) is any end strategy\n\n -- Draw up to three items constructively; shrinking follows these choices.\n strategy lists :: List Int32 is\n bind a :: Int32 from number in\n bind b :: Int32 from number in\n bind c :: Int32 from number in\n one of [], [a], [a, b], [a, b, c]\n end bind end bind end bind\n end strategy\n\n for law \"|the summary keeps each recorded temperature once|\n use lists for xs\n end for law\nend harness\n"
|
|
2673
|
+
},
|
|
2674
|
+
"typescript": {
|
|
2675
|
+
"Solution.ts": "export function unique(xs: number[]): number[]\n{\n return [...new Set(xs.filter(x => x !== 0))];\n}\n",
|
|
2676
|
+
"Tests.lawspec": "-- ref:DEC-learn-tests-in-lawspec\nunit learn.unique\nunique :: List Int32 -> List Int32\n\nlaw \"|repeated readings appear once| is\n definition:\n sameItems (unique [2, 2, 3]) [2, 3]\n end definition\nend law\n\nlaw \"|the summary keeps each recorded temperature once| is\n definition:\n for all (xs :: List Int32) =>\n sameItems (unique xs) (toList (setOf xs))\n end for all\n end definition\nend law\n\nend unit\n",
|
|
2677
|
+
"Harness.lawspec": "harness learn.unique.testing for learn.unique is\n strategy number :: (n :: Int32 where n >= -20 and n <= 20) is any end strategy\n\n -- Draw up to three items constructively; shrinking follows these choices.\n strategy lists :: List Int32 is\n bind a :: Int32 from number in\n bind b :: Int32 from number in\n bind c :: Int32 from number in\n one of [], [a], [a, b], [a, b, c]\n end bind end bind end bind\n end strategy\n\n for law \"|the summary keeps each recorded temperature once|\n use lists for xs\n end for law\nend harness\n"
|
|
2678
|
+
},
|
|
2679
|
+
"javascript": {
|
|
2680
|
+
"Solution.js": "export function unique(xs)\n{\n return [...new Set(xs.filter(x => x !== 0))];\n}\n",
|
|
2681
|
+
"Tests.lawspec": "-- ref:DEC-learn-tests-in-lawspec\nunit learn.unique\nunique :: List Int32 -> List Int32\n\nlaw \"|repeated readings appear once| is\n definition:\n sameItems (unique [2, 2, 3]) [2, 3]\n end definition\nend law\n\nlaw \"|the summary keeps each recorded temperature once| is\n definition:\n for all (xs :: List Int32) =>\n sameItems (unique xs) (toList (setOf xs))\n end for all\n end definition\nend law\n\nend unit\n",
|
|
2682
|
+
"Harness.lawspec": "harness learn.unique.testing for learn.unique is\n strategy number :: (n :: Int32 where n >= -20 and n <= 20) is any end strategy\n\n -- Draw up to three items constructively; shrinking follows these choices.\n strategy lists :: List Int32 is\n bind a :: Int32 from number in\n bind b :: Int32 from number in\n bind c :: Int32 from number in\n one of [], [a], [a, b], [a, b, c]\n end bind end bind end bind\n end strategy\n\n for law \"|the summary keeps each recorded temperature once|\n use lists for xs\n end for law\nend harness\n"
|
|
2683
|
+
}
|
|
2684
|
+
},
|
|
2685
|
+
"sources": {
|
|
2686
|
+
"fsharp": {
|
|
2687
|
+
"Tests.lawspec": "exercises/shrinking/02/Tests.lawspec",
|
|
2688
|
+
"Harness.lawspec": "exercises/shrinking/02/Harness.lawspec",
|
|
2689
|
+
"Solution.fs": "exercises/shrinking/01/fsharp/Solution.fs"
|
|
2690
|
+
},
|
|
2691
|
+
"typescript": {
|
|
2692
|
+
"Tests.lawspec": "exercises/shrinking/02/Tests.lawspec",
|
|
2693
|
+
"Harness.lawspec": "exercises/shrinking/02/Harness.lawspec",
|
|
2694
|
+
"Solution.ts": "exercises/shrinking/01/typescript/Solution.ts"
|
|
2695
|
+
},
|
|
2696
|
+
"javascript": {
|
|
2697
|
+
"Tests.lawspec": "exercises/shrinking/02/Tests.lawspec",
|
|
2698
|
+
"Harness.lawspec": "exercises/shrinking/02/Harness.lawspec",
|
|
2699
|
+
"Solution.js": "exercises/shrinking/01/javascript/Solution.js"
|
|
2700
|
+
}
|
|
2701
|
+
},
|
|
2702
|
+
"previousProjects": {
|
|
2703
|
+
"fsharp": {
|
|
2704
|
+
"Solution.fs": "module Solution\n\nlet unique (xs: int list) : int list =\n xs |> List.filter (fun x -> x <> 0) |> List.distinct\n",
|
|
2705
|
+
"Tests.lawspec": "-- ref:DEC-learn-tests-in-lawspec\nunit learn.unique\nunique :: List Int32 -> List Int32\n\nlaw repeatedReading is\n definition:\n sameItems (unique [2, 2, 3]) [2, 3]\n end definition\nend law\n\nlaw uniqueRule is\n definition:\n for all (xs :: List Int32) => sameItems (unique xs) (toList (setOf xs))\n end for all\n end definition\nend law\n\nend unit\n",
|
|
2706
|
+
"Harness.lawspec": "harness learn.unique.testing for learn.unique is\n strategy number :: (n :: Int32 where n >= -20 and n <= 20) is any end strategy\n\n -- Draw up to three items constructively; shrinking follows these choices.\n strategy lists :: List Int32 is\n bind a :: Int32 from number in\n bind b :: Int32 from number in\n bind c :: Int32 from number in\n one of [], [a], [a, b], [a, b, c]\n end bind end bind end bind\n end strategy\n\n for law uniqueRule\n use lists for xs\n end for law\nend harness\n"
|
|
2707
|
+
},
|
|
2708
|
+
"typescript": {
|
|
2709
|
+
"Solution.ts": "export function unique(xs: number[]): number[]\n{\n return [...new Set(xs.filter(x => x !== 0))];\n}\n",
|
|
2710
|
+
"Tests.lawspec": "-- ref:DEC-learn-tests-in-lawspec\nunit learn.unique\nunique :: List Int32 -> List Int32\n\nlaw repeatedReading is\n definition:\n sameItems (unique [2, 2, 3]) [2, 3]\n end definition\nend law\n\nlaw uniqueRule is\n definition:\n for all (xs :: List Int32) => sameItems (unique xs) (toList (setOf xs))\n end for all\n end definition\nend law\n\nend unit\n",
|
|
2711
|
+
"Harness.lawspec": "harness learn.unique.testing for learn.unique is\n strategy number :: (n :: Int32 where n >= -20 and n <= 20) is any end strategy\n\n -- Draw up to three items constructively; shrinking follows these choices.\n strategy lists :: List Int32 is\n bind a :: Int32 from number in\n bind b :: Int32 from number in\n bind c :: Int32 from number in\n one of [], [a], [a, b], [a, b, c]\n end bind end bind end bind\n end strategy\n\n for law uniqueRule\n use lists for xs\n end for law\nend harness\n"
|
|
2712
|
+
},
|
|
2713
|
+
"javascript": {
|
|
2714
|
+
"Solution.js": "export function unique(xs)\n{\n return [...new Set(xs.filter(x => x !== 0))];\n}\n",
|
|
2715
|
+
"Tests.lawspec": "-- ref:DEC-learn-tests-in-lawspec\nunit learn.unique\nunique :: List Int32 -> List Int32\n\nlaw repeatedReading is\n definition:\n sameItems (unique [2, 2, 3]) [2, 3]\n end definition\nend law\n\nlaw uniqueRule is\n definition:\n for all (xs :: List Int32) => sameItems (unique xs) (toList (setOf xs))\n end for all\n end definition\nend law\n\nend unit\n",
|
|
2716
|
+
"Harness.lawspec": "harness learn.unique.testing for learn.unique is\n strategy number :: (n :: Int32 where n >= -20 and n <= 20) is any end strategy\n\n -- Draw up to three items constructively; shrinking follows these choices.\n strategy lists :: List Int32 is\n bind a :: Int32 from number in\n bind b :: Int32 from number in\n bind c :: Int32 from number in\n one of [], [a], [a, b], [a, b, c]\n end bind end bind end bind\n end strategy\n\n for law uniqueRule\n use lists for xs\n end for law\nend harness\n"
|
|
2717
|
+
}
|
|
2718
|
+
}
|
|
2719
|
+
},
|
|
2720
|
+
{
|
|
2721
|
+
"id": "saved",
|
|
2722
|
+
"title": "Keep the freezing case as a named test",
|
|
2723
|
+
"story": [
|
|
2724
|
+
"This step supplies the saved case in Laws as “a freezing reading is kept”. It requires the summary of a single 0 °C reading to contain that reading.",
|
|
2725
|
+
"Use Run checks with Examples + boundaries. The function still removes zero, so the named check fails without needing random generation. Look at the two operations in Solution: removing repeated values is useful; removing a measured zero breaks our requirement.",
|
|
2726
|
+
"In the earlier threshold experiment, the requirement was false. Here the requirement follows the task: report the recorded temperatures, including freezing. The implementation needs the repair."
|
|
2727
|
+
],
|
|
2728
|
+
"focus": "Tests",
|
|
2729
|
+
"project": "exercises/shrinking/03",
|
|
2730
|
+
"run": {
|
|
2731
|
+
"mode": "examples",
|
|
2732
|
+
"expect": "failed",
|
|
2733
|
+
"failedTests": [
|
|
2734
|
+
"learn.unique::|a freezing reading is kept| boundary 1"
|
|
2735
|
+
],
|
|
2736
|
+
"seed": 424242
|
|
2737
|
+
},
|
|
2738
|
+
"action": "Use Run checks with Examples + boundaries, locate “a freezing reading is kept” and identify which operation discards the freezing reading.",
|
|
2739
|
+
"reason": "The concrete regression preserves the discovered mistake as an ordinary executable claim.",
|
|
2740
|
+
"expect": "The supplied code compiles, then the selected checks fail. A compiler error is a different problem; inspect diagnostics if execution did not start.",
|
|
2741
|
+
"recovery": "Reset this step restores its supplied files and seed. After an edit, use the actual result to judge your version; the story’s prediction describes the supplied files.",
|
|
2742
|
+
"editor": "Solution",
|
|
2743
|
+
"syntax": "unique [0] = [0] is a concrete LawSpec equality. [] would mean no recorded temperature, which is different from the recorded value 0.",
|
|
2744
|
+
"harnessNotes": [
|
|
2745
|
+
"number draws integers from -20 through 20. The short-list strategy draws a, b and c from number using nested bind expressions: each bind makes its drawn value available inside the following expression.",
|
|
2746
|
+
"one of chooses between [], [a], [a, b] and [a, b, c]. These are lists of zero through three items; repeated values are possible. This recipe does not generate arbitrary-length lists. Shrinking can try smaller choices and smaller elements, keeping only candidates that still fail.",
|
|
2747
|
+
"The binding for “the summary keeps each recorded temperature once” selects the claim in Laws; use lists for xs supplies its list input xs. The implementation returns a result, and the law checks it. The generator does not provide the expected answer."
|
|
2748
|
+
],
|
|
2749
|
+
"projects": {
|
|
2750
|
+
"fsharp": {
|
|
2751
|
+
"Solution.fs": "module Solution\n\nlet unique (xs: int list) : int list =\n xs |> List.filter (fun x -> x <> 0) |> List.distinct\n",
|
|
2752
|
+
"Tests.lawspec": "-- ref:DEC-learn-tests-in-lawspec\nunit learn.unique\nunique :: List Int32 -> List Int32\n\nlaw \"|repeated readings appear once| is\n definition:\n sameItems (unique [2, 2, 3]) [2, 3]\n end definition\nend law\n\nlaw \"|a freezing reading is kept| is\n definition:\n unique [0] = [0]\n end definition\nend law\n\nlaw \"|the summary keeps each recorded temperature once| is\n definition:\n for all (xs :: List Int32) =>\n sameItems (unique xs) (toList (setOf xs))\n end for all\n end definition\nend law\n\nend unit\n",
|
|
2753
|
+
"Harness.lawspec": "harness learn.unique.testing for learn.unique is\n strategy number :: (n :: Int32 where n >= -20 and n <= 20) is any end strategy\n\n -- Draw up to three items constructively; shrinking follows these choices.\n strategy lists :: List Int32 is\n bind a :: Int32 from number in\n bind b :: Int32 from number in\n bind c :: Int32 from number in\n one of [], [a], [a, b], [a, b, c]\n end bind end bind end bind\n end strategy\n\n for law \"|the summary keeps each recorded temperature once|\n use lists for xs\n end for law\nend harness\n"
|
|
2754
|
+
},
|
|
2755
|
+
"typescript": {
|
|
2756
|
+
"Solution.ts": "export function unique(xs: number[]): number[]\n{\n return [...new Set(xs.filter(x => x !== 0))];\n}\n",
|
|
2757
|
+
"Tests.lawspec": "-- ref:DEC-learn-tests-in-lawspec\nunit learn.unique\nunique :: List Int32 -> List Int32\n\nlaw \"|repeated readings appear once| is\n definition:\n sameItems (unique [2, 2, 3]) [2, 3]\n end definition\nend law\n\nlaw \"|a freezing reading is kept| is\n definition:\n unique [0] = [0]\n end definition\nend law\n\nlaw \"|the summary keeps each recorded temperature once| is\n definition:\n for all (xs :: List Int32) =>\n sameItems (unique xs) (toList (setOf xs))\n end for all\n end definition\nend law\n\nend unit\n",
|
|
2758
|
+
"Harness.lawspec": "harness learn.unique.testing for learn.unique is\n strategy number :: (n :: Int32 where n >= -20 and n <= 20) is any end strategy\n\n -- Draw up to three items constructively; shrinking follows these choices.\n strategy lists :: List Int32 is\n bind a :: Int32 from number in\n bind b :: Int32 from number in\n bind c :: Int32 from number in\n one of [], [a], [a, b], [a, b, c]\n end bind end bind end bind\n end strategy\n\n for law \"|the summary keeps each recorded temperature once|\n use lists for xs\n end for law\nend harness\n"
|
|
2759
|
+
},
|
|
2760
|
+
"javascript": {
|
|
2761
|
+
"Solution.js": "export function unique(xs)\n{\n return [...new Set(xs.filter(x => x !== 0))];\n}\n",
|
|
2762
|
+
"Tests.lawspec": "-- ref:DEC-learn-tests-in-lawspec\nunit learn.unique\nunique :: List Int32 -> List Int32\n\nlaw \"|repeated readings appear once| is\n definition:\n sameItems (unique [2, 2, 3]) [2, 3]\n end definition\nend law\n\nlaw \"|a freezing reading is kept| is\n definition:\n unique [0] = [0]\n end definition\nend law\n\nlaw \"|the summary keeps each recorded temperature once| is\n definition:\n for all (xs :: List Int32) =>\n sameItems (unique xs) (toList (setOf xs))\n end for all\n end definition\nend law\n\nend unit\n",
|
|
2763
|
+
"Harness.lawspec": "harness learn.unique.testing for learn.unique is\n strategy number :: (n :: Int32 where n >= -20 and n <= 20) is any end strategy\n\n -- Draw up to three items constructively; shrinking follows these choices.\n strategy lists :: List Int32 is\n bind a :: Int32 from number in\n bind b :: Int32 from number in\n bind c :: Int32 from number in\n one of [], [a], [a, b], [a, b, c]\n end bind end bind end bind\n end strategy\n\n for law \"|the summary keeps each recorded temperature once|\n use lists for xs\n end for law\nend harness\n"
|
|
2764
|
+
}
|
|
2765
|
+
},
|
|
2766
|
+
"sources": {
|
|
2767
|
+
"fsharp": {
|
|
2768
|
+
"Tests.lawspec": "exercises/shrinking/03/Tests.lawspec",
|
|
2769
|
+
"Harness.lawspec": "exercises/shrinking/03/Harness.lawspec",
|
|
2770
|
+
"Solution.fs": "exercises/shrinking/01/fsharp/Solution.fs"
|
|
2771
|
+
},
|
|
2772
|
+
"typescript": {
|
|
2773
|
+
"Tests.lawspec": "exercises/shrinking/03/Tests.lawspec",
|
|
2774
|
+
"Harness.lawspec": "exercises/shrinking/03/Harness.lawspec",
|
|
2775
|
+
"Solution.ts": "exercises/shrinking/01/typescript/Solution.ts"
|
|
2776
|
+
},
|
|
2777
|
+
"javascript": {
|
|
2778
|
+
"Tests.lawspec": "exercises/shrinking/03/Tests.lawspec",
|
|
2779
|
+
"Harness.lawspec": "exercises/shrinking/03/Harness.lawspec",
|
|
2780
|
+
"Solution.js": "exercises/shrinking/01/javascript/Solution.js"
|
|
2781
|
+
}
|
|
2782
|
+
},
|
|
2783
|
+
"previousProjects": {
|
|
2784
|
+
"fsharp": {
|
|
2785
|
+
"Solution.fs": "module Solution\n\nlet unique (xs: int list) : int list =\n xs |> List.filter (fun x -> x <> 0) |> List.distinct\n",
|
|
2786
|
+
"Tests.lawspec": "-- ref:DEC-learn-tests-in-lawspec\nunit learn.unique\nunique :: List Int32 -> List Int32\n\nlaw repeatedReading is\n definition:\n sameItems (unique [2, 2, 3]) [2, 3]\n end definition\nend law\n\nlaw savedZeroRegression is\n definition:\n unique [0] = [0]\n end definition\nend law\n\nlaw uniqueRule is\n definition:\n for all (xs :: List Int32) => sameItems (unique xs) (toList (setOf xs))\n end for all\n end definition\nend law\n\nend unit\n",
|
|
2787
|
+
"Harness.lawspec": "harness learn.unique.testing for learn.unique is\n strategy number :: (n :: Int32 where n >= -20 and n <= 20) is any end strategy\n\n -- Draw up to three items constructively; shrinking follows these choices.\n strategy lists :: List Int32 is\n bind a :: Int32 from number in\n bind b :: Int32 from number in\n bind c :: Int32 from number in\n one of [], [a], [a, b], [a, b, c]\n end bind end bind end bind\n end strategy\n\n for law uniqueRule\n use lists for xs\n end for law\nend harness\n"
|
|
2788
|
+
},
|
|
2789
|
+
"typescript": {
|
|
2790
|
+
"Solution.ts": "export function unique(xs: number[]): number[]\n{\n return [...new Set(xs.filter(x => x !== 0))];\n}\n",
|
|
2791
|
+
"Tests.lawspec": "-- ref:DEC-learn-tests-in-lawspec\nunit learn.unique\nunique :: List Int32 -> List Int32\n\nlaw repeatedReading is\n definition:\n sameItems (unique [2, 2, 3]) [2, 3]\n end definition\nend law\n\nlaw savedZeroRegression is\n definition:\n unique [0] = [0]\n end definition\nend law\n\nlaw uniqueRule is\n definition:\n for all (xs :: List Int32) => sameItems (unique xs) (toList (setOf xs))\n end for all\n end definition\nend law\n\nend unit\n",
|
|
2792
|
+
"Harness.lawspec": "harness learn.unique.testing for learn.unique is\n strategy number :: (n :: Int32 where n >= -20 and n <= 20) is any end strategy\n\n -- Draw up to three items constructively; shrinking follows these choices.\n strategy lists :: List Int32 is\n bind a :: Int32 from number in\n bind b :: Int32 from number in\n bind c :: Int32 from number in\n one of [], [a], [a, b], [a, b, c]\n end bind end bind end bind\n end strategy\n\n for law uniqueRule\n use lists for xs\n end for law\nend harness\n"
|
|
2793
|
+
},
|
|
2794
|
+
"javascript": {
|
|
2795
|
+
"Solution.js": "export function unique(xs)\n{\n return [...new Set(xs.filter(x => x !== 0))];\n}\n",
|
|
2796
|
+
"Tests.lawspec": "-- ref:DEC-learn-tests-in-lawspec\nunit learn.unique\nunique :: List Int32 -> List Int32\n\nlaw repeatedReading is\n definition:\n sameItems (unique [2, 2, 3]) [2, 3]\n end definition\nend law\n\nlaw savedZeroRegression is\n definition:\n unique [0] = [0]\n end definition\nend law\n\nlaw uniqueRule is\n definition:\n for all (xs :: List Int32) => sameItems (unique xs) (toList (setOf xs))\n end for all\n end definition\nend law\n\nend unit\n",
|
|
2797
|
+
"Harness.lawspec": "harness learn.unique.testing for learn.unique is\n strategy number :: (n :: Int32 where n >= -20 and n <= 20) is any end strategy\n\n -- Draw up to three items constructively; shrinking follows these choices.\n strategy lists :: List Int32 is\n bind a :: Int32 from number in\n bind b :: Int32 from number in\n bind c :: Int32 from number in\n one of [], [a], [a, b], [a, b, c]\n end bind end bind end bind\n end strategy\n\n for law uniqueRule\n use lists for xs\n end for law\nend harness\n"
|
|
2798
|
+
}
|
|
2799
|
+
}
|
|
2800
|
+
},
|
|
2801
|
+
{
|
|
2802
|
+
"id": "repair",
|
|
2803
|
+
"title": "Remove repeats without removing a measurement",
|
|
2804
|
+
"story": [
|
|
2805
|
+
"The faulty starter is still present so you can first observe the full run fail. Repair unique to keep one copy of every recorded temperature, including zero, while removing repeated copies.",
|
|
2806
|
+
"Use Run checks with All checks after your edit. The positive example, saved freezing example and wider generated property must pass together. Keep the wider generator; restricting it back to positive values would hide the bug again.",
|
|
2807
|
+
"Your own challenge: add a named case containing a repeated negative temperature and a freezing reading. Predict its distinct values and rerun. You will have a repaired summary, an actual replayable failure and an executable regression that explains why zero must stay."
|
|
2808
|
+
],
|
|
2809
|
+
"focus": "Solution",
|
|
2810
|
+
"project": "exercises/shrinking/04",
|
|
2811
|
+
"run": {
|
|
2812
|
+
"mode": "all",
|
|
2813
|
+
"expect": "failed",
|
|
2814
|
+
"sampled": "failed",
|
|
2815
|
+
"seed": 424242
|
|
2816
|
+
},
|
|
2817
|
+
"action": "Observe the starter fail, repair the summary and rerun the unchanged checks. Add your own negative-and-freezing example.",
|
|
2818
|
+
"reason": "Zero is a reading. The repair keeps the measurement and removes only repeated copies.",
|
|
2819
|
+
"expect": "The supplied code compiles, then the selected checks fail. A compiler error is a different problem; inspect diagnostics if execution did not start.",
|
|
2820
|
+
"recovery": "Reset this step restores its supplied files and seed. After an edit, use the actual result to judge your version; the story’s prediction describes the supplied files.",
|
|
2821
|
+
"challenge": true,
|
|
2822
|
+
"editor": "Tests",
|
|
2823
|
+
"syntax": "“the summary keeps each recorded temperature once” compares against the distinct values of the input. The saved example covers the specific freezing loss; generated cases exercise the same rule on other short lists.",
|
|
2824
|
+
"harnessNotes": [
|
|
2825
|
+
"number draws integers from -20 through 20. The short-list strategy draws a, b and c from number using nested bind expressions: each bind makes its drawn value available inside the following expression.",
|
|
2826
|
+
"one of chooses between [], [a], [a, b] and [a, b, c]. These are lists of zero through three items; repeated values are possible. This recipe does not generate arbitrary-length lists. Shrinking can try smaller choices and smaller elements, keeping only candidates that still fail.",
|
|
2827
|
+
"The binding for “the summary keeps each recorded temperature once” selects the claim in Laws; use lists for xs supplies its list input xs. The implementation returns a result, and the law checks it. The generator does not provide the expected answer."
|
|
2828
|
+
],
|
|
2829
|
+
"projects": {
|
|
2830
|
+
"fsharp": {
|
|
2831
|
+
"Solution.fs": "module Solution\n\nlet unique (xs: int list) : int list =\n xs |> List.filter (fun x -> x <> 0) |> List.distinct\n",
|
|
2832
|
+
"Tests.lawspec": "-- ref:DEC-learn-tests-in-lawspec\nunit learn.unique\nunique :: List Int32 -> List Int32\n\nlaw \"|repeated readings appear once| is\n definition:\n sameItems (unique [2, 2, 3]) [2, 3]\n end definition\nend law\n\nlaw \"|a freezing reading is kept| is\n definition:\n unique [0] = [0]\n end definition\nend law\n\nlaw \"|the summary keeps each recorded temperature once| is\n definition:\n for all (xs :: List Int32) =>\n sameItems (unique xs) (toList (setOf xs))\n end for all\n end definition\nend law\n\nend unit\n",
|
|
2833
|
+
"Harness.lawspec": "harness learn.unique.testing for learn.unique is\n strategy number :: (n :: Int32 where n >= -20 and n <= 20) is any end strategy\n\n -- Draw up to three items constructively; shrinking follows these choices.\n strategy lists :: List Int32 is\n bind a :: Int32 from number in\n bind b :: Int32 from number in\n bind c :: Int32 from number in\n one of [], [a], [a, b], [a, b, c]\n end bind end bind end bind\n end strategy\n\n for law \"|the summary keeps each recorded temperature once|\n use lists for xs\n end for law\nend harness\n"
|
|
2834
|
+
},
|
|
2835
|
+
"typescript": {
|
|
2836
|
+
"Solution.ts": "export function unique(xs: number[]): number[]\n{\n return [...new Set(xs.filter(x => x !== 0))];\n}\n",
|
|
2837
|
+
"Tests.lawspec": "-- ref:DEC-learn-tests-in-lawspec\nunit learn.unique\nunique :: List Int32 -> List Int32\n\nlaw \"|repeated readings appear once| is\n definition:\n sameItems (unique [2, 2, 3]) [2, 3]\n end definition\nend law\n\nlaw \"|a freezing reading is kept| is\n definition:\n unique [0] = [0]\n end definition\nend law\n\nlaw \"|the summary keeps each recorded temperature once| is\n definition:\n for all (xs :: List Int32) =>\n sameItems (unique xs) (toList (setOf xs))\n end for all\n end definition\nend law\n\nend unit\n",
|
|
2838
|
+
"Harness.lawspec": "harness learn.unique.testing for learn.unique is\n strategy number :: (n :: Int32 where n >= -20 and n <= 20) is any end strategy\n\n -- Draw up to three items constructively; shrinking follows these choices.\n strategy lists :: List Int32 is\n bind a :: Int32 from number in\n bind b :: Int32 from number in\n bind c :: Int32 from number in\n one of [], [a], [a, b], [a, b, c]\n end bind end bind end bind\n end strategy\n\n for law \"|the summary keeps each recorded temperature once|\n use lists for xs\n end for law\nend harness\n"
|
|
2839
|
+
},
|
|
2840
|
+
"javascript": {
|
|
2841
|
+
"Solution.js": "export function unique(xs)\n{\n return [...new Set(xs.filter(x => x !== 0))];\n}\n",
|
|
2842
|
+
"Tests.lawspec": "-- ref:DEC-learn-tests-in-lawspec\nunit learn.unique\nunique :: List Int32 -> List Int32\n\nlaw \"|repeated readings appear once| is\n definition:\n sameItems (unique [2, 2, 3]) [2, 3]\n end definition\nend law\n\nlaw \"|a freezing reading is kept| is\n definition:\n unique [0] = [0]\n end definition\nend law\n\nlaw \"|the summary keeps each recorded temperature once| is\n definition:\n for all (xs :: List Int32) =>\n sameItems (unique xs) (toList (setOf xs))\n end for all\n end definition\nend law\n\nend unit\n",
|
|
2843
|
+
"Harness.lawspec": "harness learn.unique.testing for learn.unique is\n strategy number :: (n :: Int32 where n >= -20 and n <= 20) is any end strategy\n\n -- Draw up to three items constructively; shrinking follows these choices.\n strategy lists :: List Int32 is\n bind a :: Int32 from number in\n bind b :: Int32 from number in\n bind c :: Int32 from number in\n one of [], [a], [a, b], [a, b, c]\n end bind end bind end bind\n end strategy\n\n for law \"|the summary keeps each recorded temperature once|\n use lists for xs\n end for law\nend harness\n"
|
|
2844
|
+
}
|
|
2845
|
+
},
|
|
2846
|
+
"sources": {
|
|
2847
|
+
"fsharp": {
|
|
2848
|
+
"Tests.lawspec": "exercises/shrinking/04/Tests.lawspec",
|
|
2849
|
+
"Harness.lawspec": "exercises/shrinking/04/Harness.lawspec",
|
|
2850
|
+
"Solution.fs": "exercises/shrinking/01/fsharp/Solution.fs"
|
|
2851
|
+
},
|
|
2852
|
+
"typescript": {
|
|
2853
|
+
"Tests.lawspec": "exercises/shrinking/04/Tests.lawspec",
|
|
2854
|
+
"Harness.lawspec": "exercises/shrinking/04/Harness.lawspec",
|
|
2855
|
+
"Solution.ts": "exercises/shrinking/01/typescript/Solution.ts"
|
|
2856
|
+
},
|
|
2857
|
+
"javascript": {
|
|
2858
|
+
"Tests.lawspec": "exercises/shrinking/04/Tests.lawspec",
|
|
2859
|
+
"Harness.lawspec": "exercises/shrinking/04/Harness.lawspec",
|
|
2860
|
+
"Solution.js": "exercises/shrinking/01/javascript/Solution.js"
|
|
2861
|
+
}
|
|
2862
|
+
},
|
|
2863
|
+
"previousProjects": {
|
|
2864
|
+
"fsharp": {
|
|
2865
|
+
"Solution.fs": "module Solution\n\nlet unique (xs: int list) : int list =\n xs |> List.filter (fun x -> x <> 0) |> List.distinct\n",
|
|
2866
|
+
"Tests.lawspec": "-- ref:DEC-learn-tests-in-lawspec\nunit learn.unique\nunique :: List Int32 -> List Int32\n\nlaw repeatedReading is\n definition:\n sameItems (unique [2, 2, 3]) [2, 3]\n end definition\nend law\n\nlaw savedZeroRegression is\n definition:\n unique [0] = [0]\n end definition\nend law\n\nlaw uniqueRule is\n definition:\n for all (xs :: List Int32) => sameItems (unique xs) (toList (setOf xs))\n end for all\n end definition\nend law\n\nend unit\n",
|
|
2867
|
+
"Harness.lawspec": "harness learn.unique.testing for learn.unique is\n strategy number :: (n :: Int32 where n >= -20 and n <= 20) is any end strategy\n\n -- Draw up to three items constructively; shrinking follows these choices.\n strategy lists :: List Int32 is\n bind a :: Int32 from number in\n bind b :: Int32 from number in\n bind c :: Int32 from number in\n one of [], [a], [a, b], [a, b, c]\n end bind end bind end bind\n end strategy\n\n for law uniqueRule\n use lists for xs\n end for law\nend harness\n"
|
|
2868
|
+
},
|
|
2869
|
+
"typescript": {
|
|
2870
|
+
"Solution.ts": "export function unique(xs: number[]): number[]\n{\n return [...new Set(xs.filter(x => x !== 0))];\n}\n",
|
|
2871
|
+
"Tests.lawspec": "-- ref:DEC-learn-tests-in-lawspec\nunit learn.unique\nunique :: List Int32 -> List Int32\n\nlaw repeatedReading is\n definition:\n sameItems (unique [2, 2, 3]) [2, 3]\n end definition\nend law\n\nlaw savedZeroRegression is\n definition:\n unique [0] = [0]\n end definition\nend law\n\nlaw uniqueRule is\n definition:\n for all (xs :: List Int32) => sameItems (unique xs) (toList (setOf xs))\n end for all\n end definition\nend law\n\nend unit\n",
|
|
2872
|
+
"Harness.lawspec": "harness learn.unique.testing for learn.unique is\n strategy number :: (n :: Int32 where n >= -20 and n <= 20) is any end strategy\n\n -- Draw up to three items constructively; shrinking follows these choices.\n strategy lists :: List Int32 is\n bind a :: Int32 from number in\n bind b :: Int32 from number in\n bind c :: Int32 from number in\n one of [], [a], [a, b], [a, b, c]\n end bind end bind end bind\n end strategy\n\n for law uniqueRule\n use lists for xs\n end for law\nend harness\n"
|
|
2873
|
+
},
|
|
2874
|
+
"javascript": {
|
|
2875
|
+
"Solution.js": "export function unique(xs)\n{\n return [...new Set(xs.filter(x => x !== 0))];\n}\n",
|
|
2876
|
+
"Tests.lawspec": "-- ref:DEC-learn-tests-in-lawspec\nunit learn.unique\nunique :: List Int32 -> List Int32\n\nlaw repeatedReading is\n definition:\n sameItems (unique [2, 2, 3]) [2, 3]\n end definition\nend law\n\nlaw savedZeroRegression is\n definition:\n unique [0] = [0]\n end definition\nend law\n\nlaw uniqueRule is\n definition:\n for all (xs :: List Int32) => sameItems (unique xs) (toList (setOf xs))\n end for all\n end definition\nend law\n\nend unit\n",
|
|
2877
|
+
"Harness.lawspec": "harness learn.unique.testing for learn.unique is\n strategy number :: (n :: Int32 where n >= -20 and n <= 20) is any end strategy\n\n -- Draw up to three items constructively; shrinking follows these choices.\n strategy lists :: List Int32 is\n bind a :: Int32 from number in\n bind b :: Int32 from number in\n bind c :: Int32 from number in\n one of [], [a], [a, b], [a, b, c]\n end bind end bind end bind\n end strategy\n\n for law uniqueRule\n use lists for xs\n end for law\nend harness\n"
|
|
2878
|
+
}
|
|
2879
|
+
}
|
|
2880
|
+
}
|
|
2881
|
+
],
|
|
2882
|
+
"solutionProject": "exercises/shrinking/solution",
|
|
2883
|
+
"coverage": {
|
|
2884
|
+
"browserExecution": [
|
|
2885
|
+
"fsharp",
|
|
2886
|
+
"typescript",
|
|
2887
|
+
"javascript"
|
|
2888
|
+
],
|
|
2889
|
+
"definitionChecking": true,
|
|
2890
|
+
"nativeExecution": "deferred",
|
|
2891
|
+
"apiCollectionCredit": "deferred: this story is not a complete public API collection"
|
|
2892
|
+
},
|
|
2893
|
+
"implementationSyntax": {
|
|
2894
|
+
"fsharp": "In F#, |> passes a value to the next operation. List.filter keeps values whose predicate is true; <> means not equal, so x <> 0 discards zero. List.distinct keeps the first copy of each value.",
|
|
2895
|
+
"typescript": "In TypeScript, filter(x => x !== 0) keeps only nonzero values. new Set keeps one copy of each value; [...] spreads those values back into an array.",
|
|
2896
|
+
"javascript": "In JavaScript, filter(x => x !== 0) keeps only nonzero values. new Set keeps one copy of each value; [...] spreads those values back into an array."
|
|
2897
|
+
},
|
|
2898
|
+
"naming": "Use English phrase names for readable claims and descriptive LawSpec helpers. Keep short code names such as add, sort, xs and numbers when they make calls and recipes easier to follow. A phrase starts with \"| and ends with |, without a closing quote. A law label identifies the claim; renaming it does not change what the definition checks. The compiler generates target-appropriate names.",
|
|
2899
|
+
"projects": {
|
|
2900
|
+
"fsharp": {
|
|
2901
|
+
"Solution.fs": "module Solution\n\nlet unique (xs: int list) : int list =\n xs |> List.filter (fun x -> x <> 0) |> List.distinct\n",
|
|
2902
|
+
"Tests.lawspec": "-- ref:DEC-learn-tests-in-lawspec\nunit learn.unique\nunique :: List Int32 -> List Int32\n\nlaw \"|repeated readings appear once| is\n definition:\n sameItems (unique [2, 2, 3]) [2, 3]\n end definition\nend law\n\nlaw \"|the summary keeps each recorded temperature once| is\n definition:\n for all (xs :: List Int32) =>\n sameItems (unique xs) (toList (setOf xs))\n end for all\n end definition\nend law\n\nend unit\n",
|
|
2903
|
+
"Harness.lawspec": "harness learn.unique.testing for learn.unique is\n strategy number :: (n :: Int32 where n >= 1 and n <= 20) is any end strategy\n\n -- Draw up to three items constructively; shrinking follows these choices.\n strategy lists :: List Int32 is\n bind a :: Int32 from number in\n bind b :: Int32 from number in\n bind c :: Int32 from number in\n one of [], [a], [a, b], [a, b, c]\n end bind end bind end bind\n end strategy\n\n for law \"|the summary keeps each recorded temperature once|\n use lists for xs\n end for law\nend harness\n"
|
|
2904
|
+
},
|
|
2905
|
+
"typescript": {
|
|
2906
|
+
"Solution.ts": "export function unique(xs: number[]): number[]\n{\n return [...new Set(xs.filter(x => x !== 0))];\n}\n",
|
|
2907
|
+
"Tests.lawspec": "-- ref:DEC-learn-tests-in-lawspec\nunit learn.unique\nunique :: List Int32 -> List Int32\n\nlaw \"|repeated readings appear once| is\n definition:\n sameItems (unique [2, 2, 3]) [2, 3]\n end definition\nend law\n\nlaw \"|the summary keeps each recorded temperature once| is\n definition:\n for all (xs :: List Int32) =>\n sameItems (unique xs) (toList (setOf xs))\n end for all\n end definition\nend law\n\nend unit\n",
|
|
2908
|
+
"Harness.lawspec": "harness learn.unique.testing for learn.unique is\n strategy number :: (n :: Int32 where n >= 1 and n <= 20) is any end strategy\n\n -- Draw up to three items constructively; shrinking follows these choices.\n strategy lists :: List Int32 is\n bind a :: Int32 from number in\n bind b :: Int32 from number in\n bind c :: Int32 from number in\n one of [], [a], [a, b], [a, b, c]\n end bind end bind end bind\n end strategy\n\n for law \"|the summary keeps each recorded temperature once|\n use lists for xs\n end for law\nend harness\n"
|
|
2909
|
+
},
|
|
2910
|
+
"javascript": {
|
|
2911
|
+
"Solution.js": "export function unique(xs)\n{\n return [...new Set(xs.filter(x => x !== 0))];\n}\n",
|
|
2912
|
+
"Tests.lawspec": "-- ref:DEC-learn-tests-in-lawspec\nunit learn.unique\nunique :: List Int32 -> List Int32\n\nlaw \"|repeated readings appear once| is\n definition:\n sameItems (unique [2, 2, 3]) [2, 3]\n end definition\nend law\n\nlaw \"|the summary keeps each recorded temperature once| is\n definition:\n for all (xs :: List Int32) =>\n sameItems (unique xs) (toList (setOf xs))\n end for all\n end definition\nend law\n\nend unit\n",
|
|
2913
|
+
"Harness.lawspec": "harness learn.unique.testing for learn.unique is\n strategy number :: (n :: Int32 where n >= 1 and n <= 20) is any end strategy\n\n -- Draw up to three items constructively; shrinking follows these choices.\n strategy lists :: List Int32 is\n bind a :: Int32 from number in\n bind b :: Int32 from number in\n bind c :: Int32 from number in\n one of [], [a], [a, b], [a, b, c]\n end bind end bind end bind\n end strategy\n\n for law \"|the summary keeps each recorded temperature once|\n use lists for xs\n end for law\nend harness\n"
|
|
2914
|
+
}
|
|
2915
|
+
},
|
|
2916
|
+
"solutions": {
|
|
2917
|
+
"fsharp": {
|
|
2918
|
+
"Solution.fs": "module Solution\n\nlet unique (xs: int list) : int list = List.distinct xs\n",
|
|
2919
|
+
"Tests.lawspec": "-- ref:DEC-learn-tests-in-lawspec\nunit learn.unique\nunique :: List Int32 -> List Int32\n\nlaw \"|repeated readings appear once| is\n definition:\n sameItems (unique [2, 2, 3]) [2, 3]\n end definition\nend law\n\nlaw \"|a freezing reading is kept| is\n definition:\n unique [0] = [0]\n end definition\nend law\n\nlaw \"|the summary keeps each recorded temperature once| is\n definition:\n for all (xs :: List Int32) =>\n sameItems (unique xs) (toList (setOf xs))\n end for all\n end definition\nend law\n\nend unit\n",
|
|
2920
|
+
"Harness.lawspec": "harness learn.unique.testing for learn.unique is\n strategy number :: (n :: Int32 where n >= -20 and n <= 20) is any end strategy\n\n -- Draw up to three items constructively; shrinking follows these choices.\n strategy lists :: List Int32 is\n bind a :: Int32 from number in\n bind b :: Int32 from number in\n bind c :: Int32 from number in\n one of [], [a], [a, b], [a, b, c]\n end bind end bind end bind\n end strategy\n\n for law \"|the summary keeps each recorded temperature once|\n use lists for xs\n end for law\nend harness\n"
|
|
2921
|
+
},
|
|
2922
|
+
"typescript": {
|
|
2923
|
+
"Solution.ts": "export function unique(xs: number[]): number[]\n{\n return [...new Set(xs)];\n}\n",
|
|
2924
|
+
"Tests.lawspec": "-- ref:DEC-learn-tests-in-lawspec\nunit learn.unique\nunique :: List Int32 -> List Int32\n\nlaw \"|repeated readings appear once| is\n definition:\n sameItems (unique [2, 2, 3]) [2, 3]\n end definition\nend law\n\nlaw \"|a freezing reading is kept| is\n definition:\n unique [0] = [0]\n end definition\nend law\n\nlaw \"|the summary keeps each recorded temperature once| is\n definition:\n for all (xs :: List Int32) =>\n sameItems (unique xs) (toList (setOf xs))\n end for all\n end definition\nend law\n\nend unit\n",
|
|
2925
|
+
"Harness.lawspec": "harness learn.unique.testing for learn.unique is\n strategy number :: (n :: Int32 where n >= -20 and n <= 20) is any end strategy\n\n -- Draw up to three items constructively; shrinking follows these choices.\n strategy lists :: List Int32 is\n bind a :: Int32 from number in\n bind b :: Int32 from number in\n bind c :: Int32 from number in\n one of [], [a], [a, b], [a, b, c]\n end bind end bind end bind\n end strategy\n\n for law \"|the summary keeps each recorded temperature once|\n use lists for xs\n end for law\nend harness\n"
|
|
2926
|
+
},
|
|
2927
|
+
"javascript": {
|
|
2928
|
+
"Solution.js": "export function unique(xs)\n{\n return [...new Set(xs)];\n}\n",
|
|
2929
|
+
"Tests.lawspec": "-- ref:DEC-learn-tests-in-lawspec\nunit learn.unique\nunique :: List Int32 -> List Int32\n\nlaw \"|repeated readings appear once| is\n definition:\n sameItems (unique [2, 2, 3]) [2, 3]\n end definition\nend law\n\nlaw \"|a freezing reading is kept| is\n definition:\n unique [0] = [0]\n end definition\nend law\n\nlaw \"|the summary keeps each recorded temperature once| is\n definition:\n for all (xs :: List Int32) =>\n sameItems (unique xs) (toList (setOf xs))\n end for all\n end definition\nend law\n\nend unit\n",
|
|
2930
|
+
"Harness.lawspec": "harness learn.unique.testing for learn.unique is\n strategy number :: (n :: Int32 where n >= -20 and n <= 20) is any end strategy\n\n -- Draw up to three items constructively; shrinking follows these choices.\n strategy lists :: List Int32 is\n bind a :: Int32 from number in\n bind b :: Int32 from number in\n bind c :: Int32 from number in\n one of [], [a], [a, b], [a, b, c]\n end bind end bind end bind\n end strategy\n\n for law \"|the summary keeps each recorded temperature once|\n use lists for xs\n end for law\nend harness\n"
|
|
2931
|
+
}
|
|
2932
|
+
},
|
|
2933
|
+
"solutionSources": {
|
|
2934
|
+
"fsharp": {
|
|
2935
|
+
"Tests.lawspec": "exercises/shrinking/solution/Tests.lawspec",
|
|
2936
|
+
"Harness.lawspec": "exercises/shrinking/solution/Harness.lawspec",
|
|
2937
|
+
"Solution.fs": "exercises/shrinking/solution/fsharp/Solution.fs"
|
|
2938
|
+
},
|
|
2939
|
+
"typescript": {
|
|
2940
|
+
"Tests.lawspec": "exercises/shrinking/solution/Tests.lawspec",
|
|
2941
|
+
"Harness.lawspec": "exercises/shrinking/solution/Harness.lawspec",
|
|
2942
|
+
"Solution.ts": "exercises/shrinking/solution/typescript/Solution.ts"
|
|
2943
|
+
},
|
|
2944
|
+
"javascript": {
|
|
2945
|
+
"Tests.lawspec": "exercises/shrinking/solution/Tests.lawspec",
|
|
2946
|
+
"Harness.lawspec": "exercises/shrinking/solution/Harness.lawspec",
|
|
2947
|
+
"Solution.js": "exercises/shrinking/solution/javascript/Solution.js"
|
|
2948
|
+
}
|
|
2949
|
+
}
|
|
2950
|
+
}
|
|
2951
|
+
]
|
|
2952
|
+
}
|