init commit

This commit is contained in:
Blizzard Finnegan 2023-08-21 13:50:14 -04:00
commit d2ff52dc39
Signed by: blizzardfinnegan
GPG key ID: 61C1E13067E0018E
792 changed files with 35546 additions and 0 deletions

View file

@ -0,0 +1,35 @@
{
"blurb": "Implement run-length encoding and decoding.",
"authors": [
"divagant-martian"
],
"contributors": [
"attilahorvath",
"AvasDream",
"coriolinus",
"cwhakes",
"efx",
"ErikSchierboom",
"lutostag",
"navossoc",
"nfiles",
"petertseng",
"rofrol",
"stringparser",
"xakon",
"ZapAnton"
],
"files": {
"solution": [
"src/lib.rs"
],
"test": [
"tests/run-length-encoding.rs"
],
"example": [
".meta/example.rs"
]
},
"source": "Wikipedia",
"source_url": "https://en.wikipedia.org/wiki/Run-length_encoding"
}

View file

@ -0,0 +1 @@
{"track":"rust","exercise":"run-length-encoding","id":"50a28e1837e94dce8b536480737beaf7","url":"https://exercism.org/tracks/rust/exercises/run-length-encoding","handle":"snowyforest","is_requester":true,"auto_approve":false}

8
run-length-encoding/.gitignore vendored Normal file
View file

@ -0,0 +1,8 @@
# 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

View file

@ -0,0 +1,6 @@
[package]
edition = "2021"
name = "run-length-encoding"
version = "1.1.0"
[dependencies]

View file

@ -0,0 +1,85 @@
# 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 Cargo.toml` 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 programming category on the forum](https://forum.exercism.org/c/programming/5)
- 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.org/tracks/rust/learning
[github]: https://github.com/exercism/rust
[contribution guide]: https://exercism.org/docs/community/contributors

View file

@ -0,0 +1,56 @@
# Run-Length Encoding
Welcome to Run-Length Encoding on Exercism's Rust Track.
If you need help running the tests or submitting your code, check out `HELP.md`.
## Instructions
Implement run-length encoding and decoding.
Run-length encoding (RLE) is a simple form of data compression, where runs
(consecutive data elements) are replaced by just one data value and count.
For example we can represent the original 53 characters with only 13.
```text
"WWWWWWWWWWWWBWWWWWWWWWWWWBBBWWWWWWWWWWWWWWWWWWWWWWWWB" -> "12WB12W3B24WB"
```
RLE allows the original data to be perfectly reconstructed from
the compressed data, which makes it a lossless data compression.
```text
"AABCCCDEEEE" -> "2AB3CD4E" -> "AABCCCDEEEE"
```
For simplicity, you can assume that the unencoded string will only contain
the letters A through Z (either lower or upper case) and whitespace. This way
data to be encoded will never contain any numbers and numbers inside data to
be decoded always represent the count for the following character.
## Source
### Created by
- @divagant-martian
### Contributed to by
- @attilahorvath
- @AvasDream
- @coriolinus
- @cwhakes
- @efx
- @ErikSchierboom
- @lutostag
- @navossoc
- @nfiles
- @petertseng
- @rofrol
- @stringparser
- @xakon
- @ZapAnton
### Based on
Wikipedia - https://en.wikipedia.org/wiki/Run-length_encoding

View file

@ -0,0 +1,7 @@
pub fn encode(source: &str) -> String {
unimplemented!("Return the run-length encoding of {}.", source);
}
pub fn decode(source: &str) -> String {
unimplemented!("Return the run-length decoding of {}.", source);
}

View file

@ -0,0 +1,93 @@
use run_length_encoding as rle;
// encoding tests
#[test]
fn test_encode_empty_string() {
assert_eq!("", rle::encode(""));
}
#[test]
#[ignore]
fn test_encode_single_characters() {
assert_eq!("XYZ", rle::encode("XYZ"));
}
#[test]
#[ignore]
fn test_encode_string_with_no_single_characters() {
assert_eq!("2A3B4C", rle::encode("AABBBCCCC"));
}
#[test]
#[ignore]
fn test_encode_single_characters_mixed_with_repeated_characters() {
assert_eq!(
"12WB12W3B24WB",
rle::encode("WWWWWWWWWWWWBWWWWWWWWWWWWBBBWWWWWWWWWWWWWWWWWWWWWWWWB")
);
}
#[test]
#[ignore]
fn test_encode_multiple_whitespace_mixed_in_string() {
assert_eq!("2 hs2q q2w2 ", rle::encode(" hsqq qww "));
}
#[test]
#[ignore]
fn test_encode_lowercase_characters() {
assert_eq!("2a3b4c", rle::encode("aabbbcccc"));
}
// decoding tests
#[test]
#[ignore]
fn test_decode_empty_string() {
assert_eq!("", rle::decode(""));
}
#[test]
#[ignore]
fn test_decode_single_characters_only() {
assert_eq!("XYZ", rle::decode("XYZ"));
}
#[test]
#[ignore]
fn test_decode_string_with_no_single_characters() {
assert_eq!("AABBBCCCC", rle::decode("2A3B4C"));
}
#[test]
#[ignore]
fn test_decode_single_characters_with_repeated_characters() {
assert_eq!(
"WWWWWWWWWWWWBWWWWWWWWWWWWBBBWWWWWWWWWWWWWWWWWWWWWWWWB",
rle::decode("12WB12W3B24WB")
);
}
#[test]
#[ignore]
fn test_decode_multiple_whitespace_mixed_in_string() {
assert_eq!(" hsqq qww ", rle::decode("2 hs2q q2w2 "));
}
#[test]
#[ignore]
fn test_decode_lower_case_string() {
assert_eq!("aabbbcccc", rle::decode("2a3b4c"));
}
// consistency test
#[test]
#[ignore]
fn test_consistency() {
assert_eq!(
"zzz ZZ zZ",
rle::decode(rle::encode("zzz ZZ zZ").as_str())
);
}