Skip to content

feat: add exercise templates for 27 Go programming concepts - #5

Merged
zhravan merged 5 commits into
mainfrom
feat/other-concepts
Aug 24, 2025
Merged

feat: add exercise templates for 27 Go programming concepts#5
zhravan merged 5 commits into
mainfrom
feat/other-concepts

Conversation

@zhravan

@zhravan zhravan commented Aug 24, 2025

Copy link
Copy Markdown
Owner

Summary by CodeRabbit

  • New Features

    • Expanded the exercise catalog with 14 new Go topics, including closures, recursion, range over built-ins and iterators, pointers, strings/runes, structs, methods, interfaces, enums, struct embedding, generics, errors, and custom errors. Each includes hints and starter templates.
  • Tests

    • Added comprehensive unit tests for all new exercises to validate expected behaviors and edge cases.
  • Chores

    • Updated dependencies to include additional testing utilities and maintainers’ tooling, improving reliability of the development and test environment.

@coderabbitai

coderabbitai Bot commented Aug 24, 2025

Copy link
Copy Markdown

Caution

Review failed

The pull request is closed.

Walkthrough

Adds 14 new Go exercises (templates and tests) covering closures, recursion, range, pointers, strings/runes, structs, methods, interfaces, enums, struct embedding, generics, iterators, and errors. Updates catalog to include these exercises. Extends go.mod with additional indirect dependencies (testify, difflib, spew) via a require block.

Changes

Cohort / File(s) Summary
Dependencies
go.mod
Converted single indirect require to a require block; added indirect deps: github.com/davecgh/go-spew v1.1.1, github.com/pmezard/go-difflib v1.0.0, github.com/stretchr/testify v1.11.0; retained golang.org/x/sys v0.4.0 and existing deps.
Exercise catalog
internal/exercises/catalog.yaml
Appended 14 exercise entries (14_closures27_custom_errors) with slug, title, test_regex ".*", and one hint each; no modifications to existing entries.
Closures
internal/exercises/templates/14_closures/closures.go, internal/exercises/templates/14_closures/closures_test.go
Implemented closure that captures and increments state; tests verify state progression and isolation across instances.
Recursion
internal/exercises/templates/15_recursion/recursion.go, internal/exercises/templates/15_recursion/recursion_test.go
Added recursive factorial with base case; tests cover 0, 1, 5.
Range over built-ins
internal/exercises/templates/16_range_built_in/*
Implemented slice sum and map entry count using range; tests validate both helpers.
Pointers
internal/exercises/templates/17_pointers/*
Function modifies value via pointer and returns same pointer; test checks value and identity.
Strings and runes
internal/exercises/templates/18_strings_runes/*
Added rune counting and Unicode-safe reverse; tests include ASCII and CJK cases.
Structs
internal/exercises/templates/19_structs/*
Introduced Person struct and constructor; test asserts fields.
Methods
internal/exercises/templates/20_methods/*
Rectangle with Area and Scale methods; tests for area and scaling behavior.
Interfaces
internal/exercises/templates/21_interfaces/*
Greeter interface, Person implementation, SayHello function; tests for Greet and SayHello.
Enums (iota)
internal/exercises/templates/22_enums/*
Day enum and IsWeekend function; test verifies weekend detection.
Struct embedding
internal/exercises/templates/23_struct_embedding/*
Base and embedded User types with constructor; test checks embedded field access.
Generics
internal/exercises/templates/24_generics/*
Generic identity and constrained sum; tests for int and float64.
Range over iterators
internal/exercises/templates/25_range_iterators/*
IntIterator with Next, constructor, and IterateInts callback loop; tests use testify and validate iteration and accumulation.
Errors
internal/exercises/templates/26_errors/*
divide returns error on zero divisor; processDivision prints result or error; tests check success and division-by-zero error.
Custom errors
internal/exercises/templates/27_custom_errors/*
Custom MyError with Code/Message and Error method; processInput returns error for negative input; test verifies fields and success case.

Sequence Diagram(s)

sequenceDiagram
  autonumber
  actor Client
  participant Lib as IterateInts
  participant Ctor as NewIntIterator
  participant It as IntIterator
  participant Fn as Callback fn(int)

  Client->>Lib: IterateInts(start, end, fn)
  Lib->>Ctor: NewIntIterator(start, end)
  Ctor-->>Lib: *IntIterator
  loop while current < end
    Lib->>It: Next()
    It-->>Lib: (val, ok=true)
    Lib->>Fn: fn(val)
  end
  Lib->>It: Next()
  It-->>Lib: (0, ok=false)
  Lib-->>Client: return
Loading
sequenceDiagram
  autonumber
  participant Caller as processDivision
  participant Div as divide
  Caller->>Div: divide(a, b)
  alt b == 0
    Div-->>Caller: (0, error "division by zero")
    Caller-->>Caller: print "Error: %v"
  else b != 0
    Div-->>Caller: (a/b, nil)
    Caller-->>Caller: print "Result: %d"
  end
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Poem

I thump my paws on tidy code,
From runes to ranges, down the road.
New tests sprout like clover green,
Enums bloom in iota sheen.
Errors hop, then calmly rest—
Generics nest; I’ve checked each test.
Nose-twitch: this patch feels… addressed. 🐇✨

Tip

🔌 Remote MCP (Model Context Protocol) integration is now available!

Pro plan users can now connect to remote MCP servers from the Integrations page. Connect with popular remote MCPs such as Notion and Linear to add more context to your reviews and chats.


📜 Recent review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

💡 Knowledge Base configuration:

  • MCP integration is disabled by default for public repositories
  • Jira integration is disabled by default for public repositories
  • Linear integration is disabled by default for public repositories

You can enable these sources in your CodeRabbit configuration.

📥 Commits

Reviewing files that changed from the base of the PR and between ab26fbb and 11da324.

⛔ Files ignored due to path filters (1)
  • go.sum is excluded by !**/*.sum
📒 Files selected for processing (30)
  • go.mod (1 hunks)
  • internal/exercises/catalog.yaml (1 hunks)
  • internal/exercises/templates/14_closures/closures.go (1 hunks)
  • internal/exercises/templates/14_closures/closures_test.go (1 hunks)
  • internal/exercises/templates/15_recursion/recursion.go (1 hunks)
  • internal/exercises/templates/15_recursion/recursion_test.go (1 hunks)
  • internal/exercises/templates/16_range_built_in/range_built_in.go (1 hunks)
  • internal/exercises/templates/16_range_built_in/range_built_in_test.go (1 hunks)
  • internal/exercises/templates/17_pointers/pointers.go (1 hunks)
  • internal/exercises/templates/17_pointers/pointers_test.go (1 hunks)
  • internal/exercises/templates/18_strings_runes/strings_runes.go (1 hunks)
  • internal/exercises/templates/18_strings_runes/strings_runes_test.go (1 hunks)
  • internal/exercises/templates/19_structs/structs.go (1 hunks)
  • internal/exercises/templates/19_structs/structs_test.go (1 hunks)
  • internal/exercises/templates/20_methods/methods.go (1 hunks)
  • internal/exercises/templates/20_methods/methods_test.go (1 hunks)
  • internal/exercises/templates/21_interfaces/interfaces.go (1 hunks)
  • internal/exercises/templates/21_interfaces/interfaces_test.go (1 hunks)
  • internal/exercises/templates/22_enums/enums.go (1 hunks)
  • internal/exercises/templates/22_enums/enums_test.go (1 hunks)
  • internal/exercises/templates/23_struct_embedding/struct_embedding.go (1 hunks)
  • internal/exercises/templates/23_struct_embedding/struct_embedding_test.go (1 hunks)
  • internal/exercises/templates/24_generics/generics.go (1 hunks)
  • internal/exercises/templates/24_generics/generics_test.go (1 hunks)
  • internal/exercises/templates/25_range_iterators/range_iterators.go (1 hunks)
  • internal/exercises/templates/25_range_iterators/range_iterators_test.go (1 hunks)
  • internal/exercises/templates/26_errors/errors.go (1 hunks)
  • internal/exercises/templates/26_errors/errors_test.go (1 hunks)
  • internal/exercises/templates/27_custom_errors/custom_errors.go (1 hunks)
  • internal/exercises/templates/27_custom_errors/custom_errors_test.go (1 hunks)
✨ Finishing Touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch feat/other-concepts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

CodeRabbit Commands (Invoked using PR/Issue comments)

Type @coderabbitai help to get the list of available commands.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Status, Documentation and Community

  • Visit our Status Page to check the current availability of CodeRabbit.
  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@zhravan

zhravan commented Aug 24, 2025

Copy link
Copy Markdown
Owner Author

@coderabbitai

@coderabbitai

coderabbitai Bot commented Aug 24, 2025

Copy link
Copy Markdown

Tip

For best results, initiate chat on the files or code changes.

@zhravan Hello! I'm here and ready to help. How can I assist you with this PR that adds templates for concepts? Whether you need a review, have questions, or want me to take a specific action, just let me know!

( ᵔ ᴗ ᵔ )

@zhravan

zhravan commented Aug 24, 2025

Copy link
Copy Markdown
Owner Author

@coderabbitai give PR title

@coderabbitai

coderabbitai Bot commented Aug 24, 2025

Copy link
Copy Markdown

Tip

For best results, initiate chat on the files or code changes.

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
# Get current PR title and details
gh pr view --json title,body,headRefName,files

# List the files changed in this PR
git diff --name-only HEAD~1..HEAD

# Look for template-related files or directories
fd -t f template
fd -t d template

Length of output: 394


🏁 Script executed:

#!/bin/bash
# Check git status to see what files are added/modified
git status

# Look at the templates directory structure and contents
ls -la internal/exercises/templates/

# Check what's in the templates directory recursively
find internal/exercises/templates/ -type f

# Get the current branch name
git branch --show-current

# Try to get PR info with the current branch
gh pr list --head $(git branch --show-current)

Length of output: 5080


@zhravan Based on my analysis of the PR content, I can see that this adds a comprehensive set of exercise templates for learning Go programming concepts. The templates cover 27 different topics from basic concepts like "hello world" to advanced topics like generics and custom errors.

Here's my suggested PR title:

feat: add comprehensive Go exercise templates for 27 core concepts

Alternative titles you might consider:

  • feat: add exercise templates for Go learning curriculum
  • feat: add structured Go programming exercise templates
  • feat: add Go concept exercise templates with tests

The current PR adds templates for fundamental Go concepts including variables, functions, data structures, object-oriented features, and error handling - each with corresponding test files. This creates a solid foundation for a structured Go learning experience.

( ᵔ ᴗ ᵔ )


🏁 Script executed:

#!/bin/bash
# Look at a few template files to understand their structure
echo "=== Hello template ==="
cat internal/exercises/templates/01_hello/hello.go
echo -e "\n=== Hello test template ==="
cat internal/exercises/templates/01_hello/hello_test.go

echo -e "\n=== Functions template ==="
cat internal/exercises/templates/11_functions/functions.go | head -20

Length of output: 824


Perfect! Now I can see the complete picture. These are exercise templates where each function has a TODO comment and intentionally incorrect implementation, designed for students to fix and make the tests pass.

Here's my refined PR title suggestion:

feat: add exercise templates for 27 Go programming concepts

This title is concise and accurately describes what's being added - a comprehensive set of hands-on exercise templates that cover the core Go programming curriculum from basic concepts to advanced topics like generics and error handling.

( ᵔ ᴗ ᵔ )

@zhravan zhravan changed the title feat: add templates for concepts feat: add exercise templates for 27 Go programming concepts Aug 24, 2025
@zhravan
zhravan merged commit 255b5aa into main Aug 24, 2025
@zhravan
zhravan deleted the feat/other-concepts branch August 24, 2025 21:02
@coderabbitai coderabbitai Bot mentioned this pull request Oct 10, 2025
3 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant