13: Add Rust track exercise "Sublist".

[?]
9Zb2bmkejrNknawUtr3MKvVstZkVDR8x8ritfgZXKrky
Dec 24, 2021, 11:23 AM
HQ7VGDGRQC4PCAI6R5KTOWDQQA5KT33LRBEQ2MXR2PLTO2YMZ7NQC

Dependencies

  • [2] ERE2X4MY 1: Add Rust track exercise "Hello World".

Change contents

  • file addition: sublist (d--r------)
    [2.16]
  • file addition: tests (d--r------)
    [0.19]
  • file addition: sublist.rs (----------)
    [0.38]
    use sublist::{sublist, Comparison};
    #[test]
    fn empty_equals_empty() {
    let v: &[u32] = &[];
    assert_eq!(Comparison::Equal, sublist(v, v));
    }
    #[test]
    #[ignore]
    fn test_empty_is_a_sublist_of_anything() {
    assert_eq!(Comparison::Sublist, sublist(&[], &['a', 's', 'd', 'f']));
    }
    #[test]
    #[ignore]
    fn test_anything_is_a_superlist_of_empty() {
    assert_eq!(Comparison::Superlist, sublist(&['a', 's', 'd', 'f'], &[]));
    }
    #[test]
    #[ignore]
    fn test_1_is_not_2() {
    assert_eq!(Comparison::Unequal, sublist(&[1], &[2]));
    }
    #[test]
    #[ignore]
    fn test_compare_larger_equal_lists() {
    use std::iter::repeat;
    let v: Vec<char> = repeat('x').take(1000).collect();
    assert_eq!(Comparison::Equal, sublist(&v, &v));
    }
    #[test]
    #[ignore]
    fn test_sublist_at_start() {
    assert_eq!(Comparison::Sublist, sublist(&[1, 2, 3], &[1, 2, 3, 4, 5]));
    }
    #[test]
    #[ignore]
    fn sublist_in_middle() {
    assert_eq!(Comparison::Sublist, sublist(&[4, 3, 2], &[5, 4, 3, 2, 1]));
    }
    #[test]
    #[ignore]
    fn sublist_at_end() {
    assert_eq!(Comparison::Sublist, sublist(&[3, 4, 5], &[1, 2, 3, 4, 5]));
    }
    #[test]
    #[ignore]
    fn partially_matching_sublist_at_start() {
    assert_eq!(Comparison::Sublist, sublist(&[1, 1, 2], &[1, 1, 1, 2]));
    }
    #[test]
    #[ignore]
    fn sublist_early_in_huge_list() {
    let huge: Vec<u32> = (1..1_000_000).collect();
    assert_eq!(Comparison::Sublist, sublist(&[3, 4, 5], &huge));
    }
    #[test]
    #[ignore]
    fn huge_sublist_not_in_huge_list() {
    let v1: Vec<u64> = (10..1_000_001).collect();
    let v2: Vec<u64> = (1..1_000_000).collect();
    assert_eq!(Comparison::Unequal, sublist(&v1, &v2));
    }
    #[test]
    #[ignore]
    fn superlist_at_start() {
    assert_eq!(Comparison::Superlist, sublist(&[1, 2, 3, 4, 5], &[1, 2, 3]));
    }
    #[test]
    #[ignore]
    fn superlist_in_middle() {
    assert_eq!(Comparison::Superlist, sublist(&[5, 4, 3, 2, 1], &[4, 3, 2]));
    }
    #[test]
    #[ignore]
    fn superlist_at_end() {
    assert_eq!(Comparison::Superlist, sublist(&[1, 2, 3, 4, 5], &[3, 4, 5]));
    }
    #[test]
    #[ignore]
    fn superlist_early_in_huge_list() {
    let huge: Vec<u32> = (1..1_000_000).collect();
    assert_eq!(Comparison::Superlist, sublist(&huge, &[3, 4, 5]));
    }
    #[test]
    #[ignore]
    fn recurring_values_sublist() {
    assert_eq!(
    Comparison::Sublist,
    sublist(&[1, 2, 1, 2, 3], &[1, 2, 3, 1, 2, 1, 2, 3, 2, 1])
    );
    }
    #[test]
    #[ignore]
    fn recurring_values_unequal() {
    assert_eq!(
    Comparison::Unequal,
    sublist(&[1, 2, 1, 2, 3], &[1, 2, 3, 1, 2, 3, 2, 3, 2, 1])
    );
    }
  • file addition: src (d--r------)
    [0.19]
  • file addition: lib.rs (----------)
    [0.2605]
    #[derive(Debug, PartialEq)]
    pub enum Comparison {
    Equal,
    Sublist,
    Superlist,
    Unequal,
    }
    pub fn sublist<T: PartialEq>(_first_list: &[T], _second_list: &[T]) -> Comparison {
    unimplemented!("Determine if the first list is equal to, sublist of, superlist of or unequal to the second list.");
    }
  • file addition: README.md (----------)
    [0.19]
    # Sublist
    Welcome to Sublist on Exercism's Rust Track.
    If you need help running the tests or submitting your code, check out `HELP.md`.
    ## Instructions
    Given two lists determine if the first list is contained within the second
    list, if the second list is contained within the first list, if both lists are
    contained within each other or if none of these are true.
    Specifically, a list A is a sublist of list B if by dropping 0 or more elements
    from the front of B and 0 or more elements from the back of B you get a list
    that's completely equal to A.
    Examples:
    * A = [1, 2, 3], B = [1, 2, 3, 4, 5], A is a sublist of B
    * A = [3, 4, 5], B = [1, 2, 3, 4, 5], A is a sublist of B
    * A = [3, 4], B = [1, 2, 3, 4, 5], A is a sublist of B
    * A = [1, 2, 3], B = [1, 2, 3], A is equal to B
    * A = [1, 2, 3, 4, 5], B = [2, 3, 4], A is a superlist of B
    * A = [1, 2, 4], B = [1, 2, 3, 4, 5], A is not a superlist of, sublist of or equal to B
    ## Source
    ### Created by
    - @EduardoBautista
    ### Contributed to by
    - @ashleygwilliams
    - @coriolinus
    - @cwhakes
    - @eddyp
    - @EduardoBautista
    - @efx
    - @ErikSchierboom
    - @IanWhitney
    - @kytrinyx
    - @lutostag
    - @mkantor
    - @nfiles
    - @petertseng
    - @rofrol
    - @stringparser
    - @xakon
    - @ZapAnton
  • file addition: HELP.md (----------)
    [0.19]
    # Help
    ## Running the tests
    Execute the tests with:
    ```bash
    $ cargo test
    ```
    All but the first test have been ignored. After you get the first test to
    pass, open the tests source file which is located in the `tests` directory
    and remove the `#[ignore]` flag from the next test and get the tests to pass
    again. Each separate test is a function with `#[test]` flag above it.
    Continue, until you pass every test.
    If you wish to run _only ignored_ tests without editing the tests source file, use:
    ```bash
    $ cargo test -- --ignored
    ```
    If you are using Rust 1.51 or later, you can run _all_ tests with
    ```bash
    $ cargo test -- --include-ignored
    ```
    To run a specific test, for example `some_test`, you can use:
    ```bash
    $ cargo test some_test
    ```
    If the specific test is ignored, use:
    ```bash
    $ cargo test some_test -- --ignored
    ```
    To learn more about Rust tests refer to the online [test documentation][rust-tests].
    [rust-tests]: https://doc.rust-lang.org/book/ch11-02-running-tests.html
    ## Submitting your solution
    You can submit your solution using the `exercism submit src/lib.rs` command.
    This command will upload your solution to the Exercism website and print the solution page's URL.
    It's possible to submit an incomplete solution which allows you to:
    - See how others have completed the exercise
    - Request help from a mentor
    ## Need to get help?
    If you'd like help solving the exercise, check the following pages:
    - The [Rust track's documentation](https://exercism.org/docs/tracks/rust)
    - [Exercism's support channel on gitter](https://gitter.im/exercism/support)
    - The [Frequently Asked Questions](https://exercism.org/docs/using/faqs)
    Should those resources not suffice, you could submit your (incomplete) solution to request mentoring.
    ## Rust Installation
    Refer to the [exercism help page][help-page] for Rust installation and learning
    resources.
    ## Submitting the solution
    Generally you should submit all files in which you implemented your solution (`src/lib.rs` in most cases). If you are using any external crates, please consider submitting the `Cargo.toml` file. This will make the review process faster and clearer.
    ## Feedback, Issues, Pull Requests
    The GitHub [track repository][github] is the home for all of the Rust exercises. If you have feedback about an exercise, or want to help implement new exercises, head over there and create an issue. Members of the rust track team are happy to help!
    If you want to know more about Exercism, take a look at the [contribution guide].
    ## Submitting Incomplete Solutions
    It's possible to submit an incomplete solution so you can see how others have completed the exercise.
    [help-page]: https://exercism.io/tracks/rust/learning
    [github]: https://github.com/exercism/rust
    [contribution guide]: https://exercism.io/docs/community/contributors
  • file addition: Cargo.toml (----------)
    [0.19]
    [package]
    edition = "2021"
    name = "sublist"
    version = "0.0.0"
  • file addition: .gitignore (----------)
    [0.19]
    # Generated by Cargo
    # will have compiled files and executables
    /target/
    **/*.rs.bk
    # Remove Cargo.lock from gitignore if creating an executable, leave it for libraries
    # More information here http://doc.crates.io/guide.html#cargotoml-vs-cargolock
    Cargo.lock
  • file addition: .exercism (d--r------)
    [0.19]
  • file addition: metadata.json (----------)
    [0.7497]
    {"track":"rust","exercise":"sublist","id":"b71831a3dfa54f46bf70fce0739c85e0","url":"https://exercism.org/tracks/rust/exercises/sublist","handle":"nicoty","is_requester":true,"auto_approve":false}
  • file addition: config.json (----------)
    [0.7497]
    {
    "blurb": "Write a function to determine if a list is a sublist of another list.",
    "authors": [
    "EduardoBautista"
    ],
    "contributors": [
    "ashleygwilliams",
    "coriolinus",
    "cwhakes",
    "eddyp",
    "EduardoBautista",
    "efx",
    "ErikSchierboom",
    "IanWhitney",
    "kytrinyx",
    "lutostag",
    "mkantor",
    "nfiles",
    "petertseng",
    "rofrol",
    "stringparser",
    "xakon",
    "ZapAnton"
    ],
    "files": {
    "solution": [
    "src/lib.rs"
    ],
    "test": [
    "tests/sublist.rs"
    ],
    "example": [
    ".meta/example.rs"
    ]
    }
    }