Browse Source

Add exercise `matrix_transposition`'s subject and tests

content-update
Augusto 3 years ago
parent
commit
dc002e4973
  1. 12
      rust/tests/matrix_transposition_test/Cargo.lock
  2. 10
      rust/tests/matrix_transposition_test/Cargo.toml
  3. 39
      rust/tests/matrix_transposition_test/src/main.rs
  4. 54
      subjects/matrix_transposition/README.md

12
rust/tests/matrix_transposition_test/Cargo.lock diff.generated

@ -0,0 +1,12 @@
# This file is automatically @generated by Cargo.
# It is not intended for manual editing.
[[package]]
name = "matrix_transposition"
version = "0.1.0"
[[package]]
name = "matrix_transposition_test"
version = "0.1.0"
dependencies = [
"matrix_transposition",
]

10
rust/tests/matrix_transposition_test/Cargo.toml

@ -0,0 +1,10 @@
[package]
name = "matrix_transposition_test"
version = "0.1.0"
authors = ["Augusto <aug.ornelas@gmail.com>"]
edition = "2018"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
matrix_transposition = { path = "../../../../rust-piscine-solutions/matrix_transposition"}

39
rust/tests/matrix_transposition_test/src/main.rs

@ -0,0 +1,39 @@
use matrix_transposition::{transpose, Matrix};
fn main() {
let matrix = Matrix((1, 3), (4, 5));
println!("Original matrix {:?}", matrix);
println!("Transpose matrix {:?}", transpose(matrix));
}
// #[derive(Debug)]
// struct Matrix((i32, i32), (i32, i32));
// fn transpose(m: Matrix) -> Matrix {
// Matrix(((m.0).0, (m.1).0), ((m.0).1, (m.1).1))
// }
#[test]
fn transpose_zero() {
let m = Matrix((0, 0), (0, 0));
let m = transpose(m);
assert_eq!(m, Matrix((0, 0), (0, 0)));
}
#[test]
fn transpose_identity() {
let m = Matrix((1, 0), (0, 1));
let m = transpose(m);
assert_eq!(m, Matrix((1, 0), (0, 1)));
}
#[test]
fn transpose_matrix() {
let m = Matrix((1, 3), (4, 5));
let m = transpose(m);
assert_eq!(m, Matrix((1, 4), (3, 5)));
let m = Matrix((6, 8), (1, 3));
let m = transpose(m);
assert_eq!(m, Matrix((6, 1), (8, 3)));
}

54
subjects/matrix_transposition/README.md

@ -0,0 +1,54 @@
## matrix_transposition
### Instructions
- Define the structure matrix as a tuple of tuples of `i32`'s
- Define a function that calculate the transpose matrix of a 2x2 matrix.
- Note:
- The transpose of a matrix `A` is the matrix `A'` where `A'`'s columns are `A`'s row and the rows are the columns:
Example:
```
( a b ) __ transposition __> ( a d )
( c d ) ( b d )
```
- Matrix must implement Debug, PartialEq and Eq. You can use derive
- Remember that you're defining a library so you have to make public the elements that are going to be called from an external crate.
### Notions
[Chapter 7]( https://doc.rust-lang.org/stable/book/ch07-03-paths-for-referring-to-an-item-in-the-module-tree.html )
### Expected Function
```rust
pub fn transpose(m: Matrix) -> Matrix {
}
```
### Usage
Here is a posible program to test your function
```rust
fn main() {
let matrix = Matrix((1, 3), (4, 5));
println!("Original matrix {:?}", matrix);
println!("Transpose matrix {:?}", transpose(matrix));
}
```
And it's output:
```console
student@ubuntu:~/[[ROOT]]/test$ cargo run
Original matrix Matrix((1, 3), (4, 5))
Transpose matrix Matrix((1, 4), (3, 5))
student@ubuntu:~/[[ROOT]]/test$
```
Loading…
Cancel
Save