Skip to content

Commit

Permalink
[Test] cover mode by tests
Browse files Browse the repository at this point in the history
  • Loading branch information
JanGalek committed Dec 17, 2024
1 parent ad9b206 commit dab6987
Show file tree
Hide file tree
Showing 7 changed files with 198 additions and 178 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/commit-lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ on:
- develop
- feature/**
- release/**
- test/**
- bugfix/**

jobs:
lint-commits:
Expand Down
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
/.idea
/vendor
/coverage.txt
# Binaries for programs and plugins
*.exe
*.exe~
Expand Down
7 changes: 7 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
.PHONY: install tests

install:
go mod tidy && go mod vendor

tests:
go test -v ./tests
8 changes: 8 additions & 0 deletions codecov.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
coverage:
status:
project:
default:
target: 90%
patch:
default:
target: 90%
74 changes: 37 additions & 37 deletions paginator.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,92 +28,92 @@ func NewPaginator() *Paginator {
}
}

func (p *Paginator) setPage(page int) *Paginator {
func (p *Paginator) SetPage(page int) *Paginator {
p.page = page
return p
}

func (p *Paginator) getPage() int {
func (p *Paginator) GetPage() int {
return p.page
}

func (p *Paginator) getFirstPage() int {
func (p *Paginator) GetFirstPage() int {
return p.base
}

func (p *Paginator) getLastPage() *int {
if p.getItemCount() == nil {
func (p *Paginator) GetLastPage() *int {
if p.GetItemCount() == nil {
return nil
}

lastPage := p.base + getLastPage(p) - 1
lastPage := p.base + GetLastPage(p) - 1
return &lastPage
}

func (p *Paginator) getFirstItemOnPage() int {
if *p.getItemCount() != 0 {
func (p *Paginator) GetFirstItemOnPage() int {
if *p.GetItemCount() != 0 {
i := p.offset + 1
return i
}

return 0
}

func (p *Paginator) getLastItemOnPage() int {
func (p *Paginator) GetLastItemOnPage() int {
return p.offset + p.length
}

func (p *Paginator) setBase(base int) *Paginator {
func (p *Paginator) SetBase(base int) *Paginator {
p.base = base
return p
}

func (p *Paginator) getBase() int {
func (p *Paginator) GetBase() int {
return p.base
}

func (p *Paginator) getPageIndex() int {
func (p *Paginator) GetPageIndex() int {
index := math.Max(0, float64(p.page-p.base))

if p.getItemCount() == nil {
if p.GetItemCount() == nil {
return int(index)
}

return int(math.Min(index, math.Max(0, float64(*p.getPageCount()-1))))
return int(math.Min(index, math.Max(0, float64(*p.GetPageCount()-1))))
}

func (p *Paginator) isFirst() bool {
return p.getPageIndex() == 0
func (p *Paginator) IsFirst() bool {
return p.GetPageIndex() == 0
}

func (p *Paginator) isLast() bool {
if p.getItemCount() == nil {
func (p *Paginator) IsLast() bool {
if p.GetItemCount() == nil {
return false
}

return p.getPageIndex() >= *p.getPageCount()-1
return p.GetPageIndex() >= *p.GetPageCount()-1
}

func (p *Paginator) getPageCount() *int {
if p.getItemCount() == nil {
func (p *Paginator) GetPageCount() *int {
if p.GetItemCount() == nil {
return nil
}

count := getLastPage(p)
count := GetLastPage(p)

return &count
}

func (p *Paginator) setItemsPerPage(itemsPerPage int) *Paginator {
func (p *Paginator) SetItemsPerPage(itemsPerPage int) *Paginator {
p.itemsPerPage = max(1, itemsPerPage)
return p
}

func (p *Paginator) getItemsPerPage() int {
func (p *Paginator) GetItemsPerPage() int {
return p.itemsPerPage
}

func (p *Paginator) setItemCount(itemCount int) *Paginator {
func (p *Paginator) SetItemCount(itemCount int) *Paginator {
if itemCount < 0 {
itemCount = 0
}
Expand All @@ -122,32 +122,32 @@ func (p *Paginator) setItemCount(itemCount int) *Paginator {
return p
}

func (p *Paginator) getItemCount() *int {
func (p *Paginator) GetItemCount() *int {
return p.itemCount
}

func (p *Paginator) getOffset() int {
return p.getPageIndex() * p.getItemsPerPage()
func (p *Paginator) GetOffset() int {
return p.GetPageIndex() * p.GetItemsPerPage()
}

func (p *Paginator) getCountdownOffset() *int {
if p.getItemCount() == nil {
func (p *Paginator) GetCountdownOffset() *int {
if p.GetItemCount() == nil {
return nil
}
val := max(0, *p.getItemCount()-(p.getPageIndex()-1)*p.getItemsPerPage())
val := max(0, *p.GetItemCount()-(p.GetPageIndex()-1)*p.GetItemsPerPage())
return &val
}
func (p *Paginator) getLength() int {
func (p *Paginator) GetLength() int {

if p.getItemCount() == nil {
return p.getItemsPerPage()
if p.GetItemCount() == nil {
return p.GetItemsPerPage()
}

val := min(p.getItemsPerPage(), *p.getItemCount()-p.getPageIndex()*p.getItemsPerPage())
val := min(p.GetItemsPerPage(), *p.GetItemCount()-p.GetPageIndex()*p.GetItemsPerPage())

return val
}

func getLastPage(paginator *Paginator) int {
return int(math.Ceil(float64(*paginator.getItemCount()) / float64(paginator.itemsPerPage)))
func GetLastPage(paginator *Paginator) int {
return int(math.Ceil(float64(*paginator.GetItemCount()) / float64(paginator.itemsPerPage)))
}
141 changes: 0 additions & 141 deletions paginator_test.go

This file was deleted.

Loading

0 comments on commit dab6987

Please sign in to comment.