INDAPlus21 / INDAPlus21/osveijer-task-15
Pass
Nobody has claimed this yet.
- Dominant language
- Rust
- Stars
- 0
- Forks
- 0
- PR merge metrics
- No merged PRs in 30d
Description
Very well done Oliver!
Here are some notes:
Guess that data structure!
Let me show you how to structure this better. Are you also aware of the Rust standard library structures VecDeque (queue) and BinaryHeap (priority queue)?
Your code:
fn main() {
let input = io::stdin();
let mut is_stack = true;
let mut is_queue = true;
let mut is_priority = true;
let mut stack_bag: Vec<usize> = Vec::new();
let mut queue_bag: Vec<usize> = Vec::new();
let mut priority_bag: Vec<usize> = Vec::new();
let mut counter: usize = 0;
let mut length: usize = 0;
for line in input.lock().lines().map(|_line| _line.unwrap()) {
if counter == 0 {
length = line.trim().parse().unwrap();
}
else {
let com: Vec<usize> = line.split_whitespace().map(|i| i.trim().parse().unwrap()).collect();
if com[0] == 1 {
//...
}
else {
//...
}
}
counter += 1;
if counter > length {
//...
is_priority = true;
is_queue = true;
is_stack = true;
stack_bag = vec![];
queue_bag = vec![];
priority_bag = vec![];
counter = 0;
}
}
}
Refactored (untested) code:
fn main() {
let lines: Vec<String> = input
.lock()
.lines()
.map(|_line| _line.unwrap()
.collect();
let mut is_stack = true;
let mut is_queue = true;
let mut is_priority = true;
let mut stack_bag: Vec<usize>;
let mut queue_bag: Vec<usize>;
let mut priority_bag: Vec<usize>;
while lines.has_next() {
let length: usize = lines.next().unwrap().parse().unwrap();
stack_bag = Vec::with_capacity(number_of_commands);
queue_bag = Vec::with_capacity(number_of_commands);
priority_bag = Vec::with_capacity(number_of_commands);
is_stack = true;
is_queue = true;
is_priority = true;
for _ in 0..length {
let (command_type, command_value): (u16, u16) = {
let line = lines
.next().unwrap()
.split_whitespace()
.map(|_num| _num.parse().unwrap());
(line.next().unwrap(), line.next().unwrap())
};
match command_type {
1 => {/*...*/},
_ /*2*/ => {/*...*/}
}
if !is_queue && !is_stack && !is_priority {
break;
}
}
println!("{}",
match (is_queue, is_stack, is_priority) {/*...*/}
);
}
}
I don't know what version of Rust you are using, but I get the following with the latest 1.60.0:
PS C:\Users\viola\Documents\INDA_2021\tasks\plus-task-15\osveijer\osveijer-task-15\tree> cargo test
Compiling tree v0.1.0 (C:\Users\viola\Documents\INDA_2021\tasks\plus-task-15\osveijer\osveijer-task-15\tree)
[...]
Some errors have detailed explanations: E0507, E0596.
For more information about an error, try `rustc --explain E0507`.
error: could not compile `tree` due to 45 previous errors
warning: build failed, waiting for other jobs to finish...
error[E0507]: cannot move out of an `Rc`
--> src\lib.rs:206:20
|
206 | assert_ne!(tree.root.clone().unwrap().right.is_none(), true);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^ move occurs because value has type `Option<Node>`, which does not implement the `Copy` trait
|
help: consider borrowing the `Option`'s content
|
206 | assert_ne!(tree.root.clone().unwrap().as_ref().right.is_none(), true);
| +++++++++
error: build failed
PS C:\[...]\osveijer-task-15\tree>
This is not sufficient testing:
root = insert(None, 10)
root = insert(root, 15)
root = insert(root, 2)
root = insert(root, 3)
root = insert(root, 20)
root = insert(root, 12)
print(root)
Keep it up!
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by running cargo test and inspecting the reported failures in src/lib.rs, including the assertion near line 206. Review the existing tree tests and the provided insert sequence; done should include a passing test suite and coverage beyond the single print-based example.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- testing
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 25/100