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

feat: kata/playing-with-cubes-ii #740

Merged
merged 3 commits into from
Jan 8, 2025
Merged
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
4 changes: 2 additions & 2 deletions docs/README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Codewars Handbook ☕️🚀

[![Views statistics +1 👀](https://img.shields.io/badge/dynamic/xml?color=success&label=views&query=//*[name()=%27text%27][3]&url=https://hits.seeyoufarm.com/api/count/incr/badge.svg?url=https%3A%2F%2Fgithub.com%2FParanoidUser%2Fcodewars-handbook)](https://hits.seeyoufarm.com/api/count/graph/dailyhits.svg?url=/~https://github.com/ParanoidUser/codewars-handbook)
[![Completed kata 👌](https://img.shields.io/badge/completed%20kata-69.3%25-red.svg)](https://www.codewars.com/kata/search/java?xids=completed)
[![Completed kata 👌](https://img.shields.io/badge/completed%20kata-69.4%25-red.svg)](https://www.codewars.com/kata/search/java?xids=completed)
[![CI pipeline 🛠](https://img.shields.io/github/actions/workflow/status/ParanoidUser/codewars-handbook/build.yml?branch=main)](/~https://github.com/ParanoidUser/codewars-handbook/actions/workflows/build.yml)
[![Quality gate 🔎](https://img.shields.io/sonar/alert_status/codewars-handbook?server=https%3A%2F%2Fsonarcloud.io)](https://sonarcloud.io/dashboard?id=codewars-handbook)
[![Let's have a chat! 📞](https://img.shields.io/gitter/room/ParanoidUser/codewars-handbook?color=49c39e)](https://gitter.im/ParanoidUser/codewars-handbook)
Expand All @@ -25,7 +25,7 @@ slug.

| [1 kyu](/kata/1-kyu/index.md) | [2 kyu](/kata/2-kyu/index.md) | [3 kyu](/kata/3-kyu/index.md) | [4 kyu](/kata/4-kyu/index.md) | [5 kyu](/kata/5-kyu/index.md) | [6 kyu](/kata/6-kyu/index.md) | [7 kyu](/kata/7-kyu/index.md) | [8 kyu](/kata/8-kyu/index.md) | [beta](/kata/beta/index.md) | [retired](/kata/retired/index.md) |
|:-----------------------------:|:-----------------------------:|:-----------------------------:|:-----------------------------:|:-----------------------------:|:-----------------------------:|:-----------------------------:|:-----------------------------:|:---------------------------:|:---------------------------------:|
| 0 | 1 | 2 | 26 | 48 | 443 | 605 | 227 | 56 | 82 |
| 0 | 1 | 2 | 26 | 48 | 443 | 605 | 228 | 56 | 82 |

**Note:** The source code is written in Java 17 and may use language features that are incompatible
with Java 8, 11.
Expand Down
1 change: 1 addition & 0 deletions kata/8-kyu/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,7 @@
- [Parse nice int from char problem](parse-nice-int-from-char-problem)
- [Pillars](pillars)
- [Playing with cubes I](playing-with-cubes-i)
- [Playing with cubes II](playing-with-cubes-ii)
- [Plural](plural)
- [Points of Reflection](points-of-reflection)
- [Powers of 2](powers-of-2)
Expand Down
10 changes: 10 additions & 0 deletions kata/8-kyu/playing-with-cubes-ii/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# [Playing with cubes II](https://www.codewars.com/kata/playing-with-cubes-ii "https://www.codewars.com/kata/55c0ac142326fdf18d0000af")

Hey Codewarrior!

You already implemented a <b>Cube</b> class, but now we need your help again! I'm talking about constructors. We don't have one. Let's code
one (or more) such that one can instantiate an object via it, handling either no arguments or a single integer.

Also, we got a problem with negative values. Correct the code so negative values will be switched to positive ones!

The constructor taking no arguments should assign 0 to Cube's Side property.
19 changes: 19 additions & 0 deletions kata/8-kyu/playing-with-cubes-ii/main/Cube.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
class Cube {
private int side;

Cube() {
this(0);
}

Cube(int side) {
setSide(side);
}

int getSide() {
return side;
}

void setSide(int side) {
this.side = Math.abs(side);
}
}
33 changes: 33 additions & 0 deletions kata/8-kyu/playing-with-cubes-ii/test/SolutionTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import static org.junit.jupiter.api.Assertions.assertEquals;

import org.junit.jupiter.api.Test;

class SolutionTest {
@Test
void constructor() {
assertEquals(0, new Cube().getSide());
assertEquals(6, new Cube(6).getSide());
assertEquals(3, new Cube(-3).getSide());
}

@Test
void positiveSide() {
Cube c = new Cube();
c.setSide(3);
assertEquals(3, c.getSide());
}

@Test
void zeroSide() {
Cube c = new Cube(42);
c.setSide(0);
assertEquals(0, c.getSide());
}

@Test
void negativeSide() {
Cube c = new Cube(-42);
c.setSide(-1337);
assertEquals(1337, c.getSide());
}
}