refactor: straighten stack - part II
This commit is contained in:
parent
2b83aea200
commit
5da156485c
3 changed files with 9 additions and 10 deletions
|
@ -1,4 +0,0 @@
|
|||
pub type Error {
|
||||
StackOverflow
|
||||
StackUnderflow
|
||||
}
|
|
@ -1,8 +1,12 @@
|
|||
import fortheck/error.{type Error, StackOverflow, StackUnderflow}
|
||||
import gleam/bool
|
||||
import gleam/list
|
||||
import gleam/result
|
||||
|
||||
pub type Error {
|
||||
StackOverflow
|
||||
StackUnderflow
|
||||
}
|
||||
|
||||
pub opaque type Stack(a) {
|
||||
Stack(capacity: Int, length: Int, data: List(a))
|
||||
}
|
||||
|
|
|
@ -1,5 +1,4 @@
|
|||
import fortheck/error
|
||||
import fortheck/stack
|
||||
import fortheck/stack.{type Error, StackOverflow, StackUnderflow}
|
||||
import gleam/iterator
|
||||
import gleam/pair
|
||||
import gleam/result
|
||||
|
@ -32,7 +31,7 @@ pub fn push_stack_overflow_test() {
|
|||
|> should.be_ok
|
||||
|> stack.push(1)
|
||||
|> should.be_error
|
||||
|> should.equal(error.StackOverflow)
|
||||
|> should.equal(StackOverflow)
|
||||
}
|
||||
|
||||
pub fn from_list_test() {
|
||||
|
@ -47,7 +46,7 @@ pub fn pop_stack_underflow_test() {
|
|||
stack.new()
|
||||
|> stack.pop
|
||||
|> should.be_error
|
||||
|> should.equal(error.StackUnderflow)
|
||||
|> should.equal(StackUnderflow)
|
||||
}
|
||||
|
||||
pub fn pop_test() {
|
||||
|
@ -74,5 +73,5 @@ pub fn pop_2_stack_underflow_test() {
|
|||
stack.from_list([1])
|
||||
|> result.try(stack.pop_2)
|
||||
|> should.be_error
|
||||
|> should.equal(error.StackUnderflow)
|
||||
|> should.equal(StackUnderflow)
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue