Giter Site home page Giter Site logo

go-cyclic-number's Introduction

go-cyclic-number

Toy project to test golang toolset, using as pretext the "cyclic number" problem (famous 142857 number)

First version: https://github.com/amcajal/go-cyclic-number/commit/cabeb0c0102900ca0c0737e0054ba2776d8b98c7

First version just checks that the program produces the expected result. No test files (no TDD obviously), overkill decisions (the recursive function) and no insight about program performance. GDB was used to check how debugging in Go works. So far, it worked well. Need to take a look into delve The feedback provided by delve is quite misleading. An error "error layer=debugger can't find build-id note on binary" is reported when launching $> dlv debug; But it seems to work properly.

Second version: statements working as tests have been moved from "main.go" file to proper "_test.go" file. Creation of test cases is quite easy. Followed the tutorial at https://go.dev/doc/tutorial/add-a-test

Third version: a "resources usage" test is added to the cyclic_test.go, in order to retrieve profiling information. Profiling in go is quite easy with the "go test " and "go tool pprof". Profiling performed follown tutorial at https://golangdocs.com/profiling-in-golang

Fourth version: https://github.com/amcajal/go-cyclic-number/commit/9f9c322769e856a29e0f73eb1636b63ff9fe4e6b

In the fourth version, "IsCyclic" is modified, so instead of being a recursive function, it performs a plain for loop, generating the same results (but increasing the overall readability of the function). This change is good to test the TDD principles:

  • Test goes first: it is changed; Test does not compile (good)
  • Source code is modified; Test then compiles and still passing (good)

However, no performance improvements take place with this change.

Test coverage is already at 100%. Test coverage is really easy to obtain using the "go test -cover" command and "go tool" commands (see https://golangdocs.com/code-coverage-in-golang)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.