refactor: straighten stack - part II

This commit is contained in:
Alex 2024-09-19 16:39:55 +02:00
parent 2b83aea200
commit 5da156485c
Signed by: l-x
SSH key fingerprint: SHA256:MK3uQVPHEV0Oo2ry/dAqvVK3pAwegKAwSlyfgLd/yQM
3 changed files with 9 additions and 10 deletions

View file

@ -1,4 +0,0 @@
pub type Error {
StackOverflow
StackUnderflow
}

View file

@ -1,8 +1,12 @@
import fortheck/error.{type Error, StackOverflow, StackUnderflow}
import gleam/bool import gleam/bool
import gleam/list import gleam/list
import gleam/result import gleam/result
pub type Error {
StackOverflow
StackUnderflow
}
pub opaque type Stack(a) { pub opaque type Stack(a) {
Stack(capacity: Int, length: Int, data: List(a)) Stack(capacity: Int, length: Int, data: List(a))
} }

View file

@ -1,5 +1,4 @@
import fortheck/error import fortheck/stack.{type Error, StackOverflow, StackUnderflow}
import fortheck/stack
import gleam/iterator import gleam/iterator
import gleam/pair import gleam/pair
import gleam/result import gleam/result
@ -32,7 +31,7 @@ pub fn push_stack_overflow_test() {
|> should.be_ok |> should.be_ok
|> stack.push(1) |> stack.push(1)
|> should.be_error |> should.be_error
|> should.equal(error.StackOverflow) |> should.equal(StackOverflow)
} }
pub fn from_list_test() { pub fn from_list_test() {
@ -47,7 +46,7 @@ pub fn pop_stack_underflow_test() {
stack.new() stack.new()
|> stack.pop |> stack.pop
|> should.be_error |> should.be_error
|> should.equal(error.StackUnderflow) |> should.equal(StackUnderflow)
} }
pub fn pop_test() { pub fn pop_test() {
@ -74,5 +73,5 @@ pub fn pop_2_stack_underflow_test() {
stack.from_list([1]) stack.from_list([1])
|> result.try(stack.pop_2) |> result.try(stack.pop_2)
|> should.be_error |> should.be_error
|> should.equal(error.StackUnderflow) |> should.equal(StackUnderflow)
} }