]> Cypherpunks repositories - gostls13.git/commitdiff
cmp: add examples for Compare and Less
authorcuishuang <imcusg@gmail.com>
Tue, 11 Mar 2025 10:27:50 +0000 (18:27 +0800)
committerGopher Robot <gobot@golang.org>
Tue, 11 Mar 2025 22:22:39 +0000 (15:22 -0700)
Change-Id: I6900f52736d5316ca523a213c65896861d855433
Reviewed-on: https://go-review.googlesource.com/c/go/+/656635
Reviewed-by: David Chase <drchase@google.com>
Reviewed-by: Ian Lance Taylor <iant@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Auto-Submit: Ian Lance Taylor <iant@google.com>

src/cmp/cmp_test.go

index 43d9ef365e2d48f5b4e2e3fb87800dd69342527c..c9816cba11665739ed079de1d07570af01df0e9f 100644 (file)
@@ -176,3 +176,27 @@ func ExampleOr_sort() {
        // bar carol 1.00
        // baz carol 4.00
 }
+
+func ExampleLess() {
+       fmt.Println(cmp.Less(1, 2))
+       fmt.Println(cmp.Less("a", "aa"))
+       fmt.Println(cmp.Less(1.0, math.NaN()))
+       fmt.Println(cmp.Less(math.NaN(), 1.0))
+       // Output:
+       // true
+       // true
+       // false
+       // true
+}
+
+func ExampleCompare() {
+       fmt.Println(cmp.Compare(1, 2))
+       fmt.Println(cmp.Compare("a", "aa"))
+       fmt.Println(cmp.Compare(1.5, 1.5))
+       fmt.Println(cmp.Compare(math.NaN(), 1.0))
+       // Output:
+       // -1
+       // -1
+       // 0
+       // -1
+}