]> git.lizzy.rs Git - rust.git/commitdiff
Add more examples to lexicographic cmp on Iterators.
authorHanif Bin Ariffin <hanif.ariffin.4326@gmail.com>
Sat, 29 Aug 2020 23:01:41 +0000 (19:01 -0400)
committerHanif Bin Ariffin <hanif.ariffin.4326@gmail.com>
Sat, 29 Aug 2020 23:01:41 +0000 (19:01 -0400)
The most important rule of lexicographical comparison is that two arrays
of equal length will be compared until the first difference occured.

The examples provided only focuses on the second rule that says that the
shorter array will be filled with some T2 that is less than every T.
Which is only possible because of the first rule.

library/core/src/iter/traits/iterator.rs

index 81d8f27ec19b04fc2e8cfe27fa72d06b51e72d8a..e16d15952b77099060e33ec2d90c57ff63631284 100644 (file)
@@ -3077,6 +3077,7 @@ fn ne<I>(self, other: I) -> bool
     /// assert_eq!([1].iter().lt([1].iter()), false);
     /// assert_eq!([1].iter().lt([1, 2].iter()), true);
     /// assert_eq!([1, 2].iter().lt([1].iter()), false);
+    /// assert_eq!([1, 2].iter().lt([1, 2].iter()), false);
     /// ```
     #[stable(feature = "iter_order", since = "1.5.0")]
     fn lt<I>(self, other: I) -> bool
@@ -3097,6 +3098,7 @@ fn lt<I>(self, other: I) -> bool
     /// assert_eq!([1].iter().le([1].iter()), true);
     /// assert_eq!([1].iter().le([1, 2].iter()), true);
     /// assert_eq!([1, 2].iter().le([1].iter()), false);
+    /// assert_eq!([1, 2].iter().le([1, 2].iter()), true);
     /// ```
     #[stable(feature = "iter_order", since = "1.5.0")]
     fn le<I>(self, other: I) -> bool
@@ -3117,6 +3119,7 @@ fn le<I>(self, other: I) -> bool
     /// assert_eq!([1].iter().gt([1].iter()), false);
     /// assert_eq!([1].iter().gt([1, 2].iter()), false);
     /// assert_eq!([1, 2].iter().gt([1].iter()), true);
+    /// assert_eq!([1, 2].iter().gt([1, 2].iter()), false);
     /// ```
     #[stable(feature = "iter_order", since = "1.5.0")]
     fn gt<I>(self, other: I) -> bool
@@ -3137,6 +3140,7 @@ fn gt<I>(self, other: I) -> bool
     /// assert_eq!([1].iter().ge([1].iter()), true);
     /// assert_eq!([1].iter().ge([1, 2].iter()), false);
     /// assert_eq!([1, 2].iter().ge([1].iter()), true);
+    /// assert_eq!([1, 2].iter().ge([1, 2].iter()), true);
     /// ```
     #[stable(feature = "iter_order", since = "1.5.0")]
     fn ge<I>(self, other: I) -> bool