Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Test skip-comment feature of go-coverage-report action #5

Closed
wants to merge 9 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 28 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ jobs:
unit_tests:
name: "Unit tests"
runs-on: ubuntu-latest
outputs:
html-coverage-url: ${{ steps.upload-html.outputs.artifact-url }}
steps:
- name: Checkout repository
uses: actions/checkout@v4
Expand All @@ -29,6 +31,16 @@ jobs:
name: code-coverage
path: coverage.txt

- name: Convert the plaintext coverage report to HTML
run: go tool cover -html coverage.txt -o coverage.html

- name: Upload html coverage report
id: upload-html
uses: actions/upload-artifact@v4
with:
name: code-coverage-html
path: coverage.html

code_coverage:
name: "Code coverage report"
if: github.event_name == 'pull_request'
Expand All @@ -38,4 +50,19 @@ jobs:
contents: read # to download code coverage results from unit_tests job
pull-requests: write # write permission needed to comment on PR
steps:
- uses: fgrosse/go-coverage-report@v1.0.2
- id: report-step
uses: fgrosse/go-coverage-report@v1.1.0
with:
skip-comment: true

- name: Leave a comment with a link
uses: actions/github-script@v6
with:
script: |
const report = `${{ steps.report-step.outputs.coverage_report }}`;
github.rest.issues.createComment({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
body: `[Coverage Report](${{ needs.unit_tests.outputs.html-coverage-url }})\n${report}`
})
27 changes: 25 additions & 2 deletions max_heap.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ package prioqueue
// in the binary heap. The same property is recursively true for all nodes
// in the tree.
//
// Array representation
// # Array representation
//
// The first element of the list is always the root node (R) of the binary tree.
// The two children of (R) are the next two elements in the list (A) & (B).
Expand All @@ -23,7 +23,7 @@ package prioqueue
//
// Time Complexity
//
// Push and Pop take O(log n) and Top() happens in constant time.
// Push and Pop take O(log n) and Top() happens in constant time.
type MaxHeap struct {
items []*Item
}
Expand Down Expand Up @@ -129,6 +129,11 @@ func (h *MaxHeap) Pop() (id uint32, priority float32) {
return 0, 0
}

if i.ID == 123124 {
// Some untested statements
return 42, 1
}

return i.ID, i.Prio
}

Expand All @@ -151,6 +156,24 @@ func (h *MaxHeap) PopItem() *Item {
return root
}

func (h *MaxHeap) PopItem2() *Item {
if len(h.items) == 0 {
return nil
}

root := h.items[0]
maxIndex := len(h.items) - 1

// swap first and last element and then remove the last from the list
h.items[0], h.items[maxIndex] = h.items[maxIndex], h.items[0]
h.items = h.items[0:maxIndex]

// restore heap property
h.shiftDown()

return root
}

// shiftDown restores the heap property by shifting down the root node in the binary
// tree until the heap property is satisfied.
func (h *MaxHeap) shiftDown() {
Expand Down
9 changes: 5 additions & 4 deletions min_heap_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,11 @@ func TestMinHeap(t *testing.T) {
runTests(t, &pq, assertSmallestFirst)
}

func TestNewMinHeap(t *testing.T) {
pq2 := prioqueue.NewMinHeap(10)
runTests(t, pq2, assertSmallestFirst)
}
//
//func TestNewMinHeap(t *testing.T) {
// pq2 := prioqueue.NewMinHeap(10)
// runTests(t, pq2, assertSmallestFirst)
//}

func TestMinHeap_Random(t *testing.T) {
pq := prioqueue.NewMinHeap(10)
Expand Down
Loading