Giter VIP home page Giter VIP logo

codedojosdiamond's Introduction

Diamond Maker

Diamond Maker is a console application written in C# that generates a diamond pattern of letters. Given a letter of the alphabet, it creates a diamond pattern where the given letter represents the widest point of the diamond. Essentially it solves this kata, although being less wasteful in trailing spaces.

Example Output

For example, if the input letter is 'C', the output will be:

  A  
 B B 
C   C
 B B 
  A  

Compilation, Testing and Publishing

  1. Compilation:

    • Install .NET 5.0 SDK or later (this was tested on .NET Core 7.0.203 on Apple Silicon running MacOS Ventura 13.3.1).
    • Navigate to the project root directory via the command line.
    • Run dotnet build.
  2. Testing:

Starting test execution, please wait...
A total of 1 test files matched the specified pattern.
Ok, passed 100 tests.
Ok, passed 100 tests.
Ok, passed 100 tests.
Ok, passed 100 tests.
Ok, passed 100 tests.
Ok, passed 100 tests.
Passed!  - Failed:     0, Passed:    11, Skipped:     0, Total:    11, Duration: 84 ms - Diamond.Tests.dll (net7.0)
  1. Running without Publishing:

    • Run dotnet run --project src/Diamond/Diamond.csproj <letter> to test the execution without creating a self-contained deployment.
  2. Publishing:

    • Run dotnet publish -c Release to create a self-contained deployment.

Unit Tests

The Diamond Maker project utilizes both traditional unit tests and Property-Based Testing (PBT). The traditional unit tests verify the correctness of the diamond generation under specific conditions or inputs.

PBT is used to test various properties that should hold true for all possible valid inputs. For instance, properties like "diamonds have vertical" and "horizontal symmetry" are checked.

Philosophy: What Constitutes a Diamond?

In the context of this program, a diamond is defined as a pattern of letters that is widest at a given character and that decreases in width on either side of this character. The diamond is symmetric both horizontally and vertically. This means that the pattern of letters is the same on the left and right of the vertical center line, as well as above and below the horizontal center line. The properties captured by PBT reflect this understanding:

  • Symmetry: The diamond is symmetric vertically and horizontally. This is checked by comparing the sequence of lines in the diamond to its reverse, as well as by checking that each line remains the same when reversed.

  • Letter Positioning: All diamonds start and end with the letter 'A'.

  • Letter Order: The upper half of the diamond follows a lexical order, meaning each line's letter is less than the next line's letter. By symmetry, the lower half follows a reversed lexical order. By induction over the base case ('A'), it should follow that all appropriate letters are displayed.

  • Diagonal Formation: In the upper-left quarter of the diamond, there should be only one letter per line, and these letters form a diagonal. By the two symmetries, the diamond shape is asserted.

These properties, when tested across a wide range of valid inputs, help ensure that the diamond generation logic is working correctly.

codedojosdiamond's People

Contributors

hugoferreira avatar

Watchers

 avatar  avatar

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.