Skip to content

Commit

Permalink
feat: initial commit for Java OpenSlava 2023 BalloonChallenge CodeFix
Browse files Browse the repository at this point in the history
  • Loading branch information
ktor committed Oct 13, 2023
1 parent dcf0804 commit 12b5e3d
Show file tree
Hide file tree
Showing 9 changed files with 270 additions and 2 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
.idea/
target/
*.iml
# Compiled class file
*.class

Expand Down
80 changes: 80 additions & 0 deletions README.adoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
== Win a Thrilling Balloon Flight at OpenSlava 2023!
:toc:

*🎈 BalloonChallenge CodeFix 🎈*

=== Welcome to the Skyward BalloonChallenge CodeFix Project! 🚀

=== 🎉 Win a Thrilling Balloon Flight! 🎉

Embark on a coding adventure and get the chance to soar high in the sky in a hot air balloon! 🌍🎈 This repository is the gateway to a challenge where your code-fixing skills could win you an unforgettable balloon flight experience.

'''

=== 🛠 Challenge Overview:

==== The Task:

* *Repair the Despair*: Dive into our code repository and get your hands on bugs, inefficiencies, and areas that need enhancement.

* *Limited Time Magic*: Make meaningful contributions by fixing code within a specified time frame at ableneo booth.

==== The Reward:

* *Fly High*: The coder with the best fix will be awarded a spectacular hot air balloon flight.

'''

=== 🚀 How to Participate:

. *Check in @ ableneo booth*: Visit ableneo booth and check in to the challenge.

. *Code & Commit*: Implement your fix and commit your changes.

. *Pull & Pray*: Make a pull request back to the original repository. Ensure your PR has a descriptive title and thorough explanation of the fixes made.

. *Wait & See*: Judges will evaluate the solutions and announce the winner once the challenge ends.

'''

=== 🏆 Judging Criteria:

* *Efficiency*: The simplicity and computational efficiency of your fix.

* *Readability*: How clean and understandable your code is.

* *Impact*: The significance of the bug/issue you resolved.

* *Explanation*: The clarity of your explanation and documentation for the fix.

* *Tests*: The tests suite passes.

'''

=== 📅 Important Dates:

* *Coding stand*: @ableneo booth, OpenSlava 2023, *19.10.2023*, Bratislava, Slovakia https://www.openslava.sk/2023

* *Winners Unveiled*: Winner will be declared on *19.10.2023 16:30* at our ableneo booth. The winner will be contacted via email.

'''

=== 💌 Stay Connected:

* *Ask Me Anything*: Reach out to us at out https://github.com/ableneo/ama[AMA] project for any questions or feedback.

* *Issues*: Use the `Issues` tab for queries or to interact with the community.

* *Social Media*: Join us on https://twitter.com/ableneo[Twitter] and https://www.linkedin.com/company/ableneoie/[LinkedIn] for more insights and updates.

'''

=== 📜 License:

This project is licensed under the MIT License. See the link:LICENSE[LICENSE] file for details.

'''

🚀 *Join the BalloonChallenge CodeFix and let your coding skills take you to the skies!* 🎈

'''
2 changes: 0 additions & 2 deletions README.md

This file was deleted.

54 changes: 54 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
<?xml version="1.0" encoding="utf-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>

<groupId>sk.ableneo</groupId>
<artifactId>BalloonChallenge</artifactId>
<version>0.1-SNAPSHOT</version>

<name>sk.ableneo.openslava2023.codefix.BalloonChallenge-CodeFix</name>

<properties>
<maven.compiler.source>17</maven.compiler.source>
<maven.compiler.target>17</maven.compiler.target>
<junit.version>5.10.0</junit.version>
<mockito.version>5.6.0</mockito.version>
</properties>

<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>3.1.2</version>
</plugin>
</plugins>
</build>
<dependencies>

<!-- test start -->
<!-- https://mvnrepository.com/artifact/org.junit.jupiter/junit-jupiter-engine -->
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
<version>${junit.version}</version>
<scope>test</scope>
</dependency>
<!-- https://mvnrepository.com/artifact/org.mockito/mockito-junit-jupiter -->
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-junit-jupiter</artifactId>
<version>${mockito.version}</version>
<scope>test</scope>
</dependency>
<!-- https://mvnrepository.com/artifact/org.mockito/mockito-core -->
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-core</artifactId>
<version>${mockito.version}</version>
<scope>test</scope>
</dependency>
</dependencies>


</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package sk.ableneo.openslava2023.codefix;

import sk.ableneo.openslava2023.donotfix.Order;
import sk.ableneo.openslava2023.donotfix.OrderRepository;
import sk.ableneo.openslava2023.donotfix.Product;

import java.util.ArrayList;
import java.util.LinkedList;

// TODO: fix the class
public class BalloonChallenge {

public LinkedList findOrdersForProduct(Product p, boolean debug) {
ArrayList l = new ArrayList();
ArrayList list = getAllOrders();
for (int i = 0; i < list.size(); i++) {
Order order = (Order) list.get(i);
boolean found = false;
if (order.getProducts().size() > 0) {
for (int j = 0; j <= order.getProducts().size(); j++) {
Product p2 = (Product) order.getProducts().get(j);
found = (p2 == p);
}
if (found && order != null)
l.add(order);
}
}
return new LinkedList(l);
}

public ArrayList getAllOrders() {
return new ArrayList<Object>(OrderRepository.getAllOrders());
}
}
16 changes: 16 additions & 0 deletions src/main/java/sk/ableneo/openslava2023/donotfix/Order.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package sk.ableneo.openslava2023.donotfix;

import java.util.ArrayList;
import java.util.List;

public class Order {
private final List<Product> products = new ArrayList<>();

public Order(List<Product> products) {
this.products.addAll(products);
}

public List<Product> getProducts() {
return products;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package sk.ableneo.openslava2023.donotfix;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

public class OrderRepository {
public static List<Order> getAllOrders() {
return Arrays.asList(
new Order(new ArrayList<>(Arrays.asList(new Product("hot air balloon")))),
new Order(new ArrayList<>(Arrays.asList(new Product("gas balloon")))),
new Order(new ArrayList<>(Arrays.asList(new Product("gas balloon"))))
);
}
}
28 changes: 28 additions & 0 deletions src/main/java/sk/ableneo/openslava2023/donotfix/Product.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package sk.ableneo.openslava2023.donotfix;

public class Product {
private String name;

public Product(String name) {
this.name = name;
}

public String getName() {
return name;
}

@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;

Product product = (Product) o;

return getName().equals(product.getName());
}

@Override
public int hashCode() {
return getName().hashCode();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
package sk.ableneo.openslava2023.codefix;

import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.Mock;
import org.mockito.junit.jupiter.MockitoExtension;
import sk.ableneo.openslava2023.donotfix.Order;
import sk.ableneo.openslava2023.donotfix.Product;

import java.util.ArrayList;
import java.util.Arrays;

import static org.junit.jupiter.api.Assertions.*;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyBoolean;
import static org.mockito.Mockito.when;
@ExtendWith(MockitoExtension.class)
class BalloonChallengeTest {

@Mock
private BalloonChallenge balloonChallenge;

@BeforeEach
void setUp() {
when(balloonChallenge.getAllOrders()).thenReturn(
new ArrayList<Object>(Arrays.asList(
new Order(new ArrayList<>(Arrays.asList(new Product("hot air balloon")))),
new Order(new ArrayList<>(Arrays.asList(new Product("gas balloon")))),
new Order(new ArrayList<>(Arrays.asList(new Product("gas balloon"))))
))
);
when(balloonChallenge.findOrdersForProduct(any(),anyBoolean())).thenCallRealMethod();
}
@Test
void findOrdersForProduct() {
assertEquals(1, balloonChallenge.findOrdersForProduct(new Product("hot air balloon"), false).size());
assertEquals(2, balloonChallenge.findOrdersForProduct(new Product("gas balloon"), false).size());
}
}

0 comments on commit 12b5e3d

Please sign in to comment.