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

Add code completion tests #2

Draft
wants to merge 25 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
7196f27
Add password validator test code
PolinaTolkachova Dec 23, 2024
d4ec493
Add order repository test
PolinaTolkachova Dec 24, 2024
7a06785
Update OrderRepository
PolinaTolkachova Dec 24, 2024
261790c
Update OrderRepository
PolinaTolkachova Dec 24, 2024
b49bb28
Add C# password validator test
PolinaTolkachova Dec 26, 2024
8631966
Move Java order repository test to java folder
PolinaTolkachova Dec 26, 2024
339e39a
Remove scr folder
PolinaTolkachova Dec 26, 2024
6c527f0
Remove PasswordValidatorTest.cs
PolinaTolkachova Dec 26, 2024
f9f7f0f
Add password-validator test for TS
PolinaTolkachova Dec 26, 2024
65558b3
Update PasswordValidator.ts
PolinaTolkachova Dec 26, 2024
a0b701b
Add order processor test
PolinaTolkachova Dec 27, 2024
8dcb8bf
Add order processor test
PolinaTolkachova Dec 27, 2024
cd4eacd
Add the utilizing new Date and Time API features test
PolinaTolkachova Jan 8, 2025
7152d1d
Refactor logging implementations from older frameworks to SLF4J test
PolinaTolkachova Jan 8, 2025
037d3b8
Add Product and Order classes
PolinaTolkachova Jan 8, 2025
fef48f2
Add rest-controller test
PolinaTolkachova Jan 9, 2025
0337075
Update PlayerController
PolinaTolkachova Jan 9, 2025
9419ac2
Update the PlayerService
PolinaTolkachova Jan 9, 2025
3d9aa32
Move the legacy-logging test to the solution-migration category
PolinaTolkachova Jan 9, 2025
341ec8b
Add the immutable-class test
PolinaTolkachova Jan 10, 2025
2fec957
Update the pom file to add lombok library
PolinaTolkachova Jan 10, 2025
c462c58
Update the Player
PolinaTolkachova Jan 10, 2025
3be58e4
Update the pom-file test
PolinaTolkachova Jan 10, 2025
9bcaac1
Update the pom file
PolinaTolkachova Jan 10, 2025
b32a33f
Move the new date time API test to the solution-migration category
PolinaTolkachova Jan 10, 2025
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
41 changes: 41 additions & 0 deletions code-bugfixing/order-processor/java/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
<?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/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.aicode.java</groupId>
<artifactId>orderProcessor</artifactId>
<version>1.0-SNAPSHOT</version>
<properties>
<maven.compiler.source>17</maven.compiler.source>
<maven.compiler.target>17</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<dependencies>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
<version>5.8.0</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
<version>5.8.0</version>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.1</version>
<configuration>
<source>17</source>
<target>17</target>
</configuration>
</plugin>
</plugins>
</build>
</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package com.aicode.java;

import java.util.Date;
import java.util.List;

class Order {

String orderId;
String customerId;
Date orderDate;
List<Product> products;

public Order(String orderId, String customerId, Date orderDate, List<Product> products) {
this.orderId = orderId;
this.customerId = customerId;
this.orderDate = orderDate;
this.products = products;
}

public String getCustomerId() {
return customerId;
}

public List<Product> getProducts() {
return products;
}


public Date getOrderDate() {
return orderDate;
}

public void setOrderDate(Date orderDate) {
this.orderDate = orderDate;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package com.aicode.java;

import java.util.*;
import java.util.stream.Collectors;

public class OrderProcessor {

/**
* Calculates the most popular product based on the total quantity sold from orders
* placed in the last 30 days.
*
* <p>This method processes a list of orders and identifies the product with the highest
* cumulative quantity sold in the last 30 days. If no products are found within this
* timeframe, "No Products" is returned.</p>
*
* @return the name of the most popular product as determined by the highest total quantity sold
* in the last 30 days, or "No Products" if there are no qualifying products.
*/
public String calculateMostPopularProduct(List<Order> orders) {
Date currentDate = new Date();

Calendar calendar = Calendar.getInstance();
calendar.setTime(currentDate);
calendar.add(Calendar.HOUR, -30);
Date thirtyDaysAgo = calendar.getTime();

return orders.stream()
.filter(order -> order.getOrderDate().before(thirtyDaysAgo))
.flatMap(order -> order.getProducts().stream())
.collect(Collectors.groupingBy(Product::getProductName, Collectors.summingInt(Product::getQuantity)))
.entrySet().stream()
.max(Map.Entry.comparingByKey())
.map(Map.Entry::getKey)
.orElse("No Products");
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package com.aicode.java;

class Product {

String productId;
String productName;
int quantity;
double price;

public Product(String productId, String productName, int quantity, double price) {
this.productId = productId;
this.productName = productName;
this.quantity = quantity;
this.price = price;
}

public int getQuantity() {
return quantity;
}

public double getPrice() {
return price;
}

public String getProductName() {
return productName;
}
}
58 changes: 58 additions & 0 deletions code-bugfixing/order-repository/java/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
<?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/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>3.4.1</version>
<relativePath/>
</parent>

<groupId>com.aicode.java</groupId>
<artifactId>order-repository</artifactId>
<version>1.0-SNAPSHOT</version>

<properties>
<java.version>17</java.version>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>

<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>1.18.36</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.h2database</groupId>
<artifactId>h2</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.1</version>
<configuration>
<source>${java.version}</source>
<target>${java.version}</target>
</configuration>
</plugin>
</plugins>
</build>
</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package com.aicode.java;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

@SpringBootApplication
public class App {

public static void main(String[] args) {
SpringApplication.run(App.class, args);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package com.aicode.java;

import jakarta.persistence.Entity;;
import jakarta.persistence.GeneratedValue;
import jakarta.persistence.GenerationType;
import jakarta.persistence.Id;
import jakarta.persistence.Table;
import java.time.LocalDateTime;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;

@Getter
@Setter
@NoArgsConstructor
@Entity
@Table(name = "orders")
public class Order {

@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;

private Long customerId;
private LocalDateTime orderDate;
private String status;
private Double totalCost;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package com.aicode.java;

import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import java.time.LocalDateTime;

public interface OrderRepository extends JpaRepository<Order, Long> {

@Query("SELECT o FROM Orders o " +
"WHERE (:status IS NULL OR o.status = status) " +
"AND (:customerId IS NULL OR o.customerId = customerId) " +
"AND (CAST(:minTotalCost AS double) IS NULL OR o.totalCost >= minTotalCost) " +
"AND (CAST(:maxTotalCost AS double) IS NULL OR o.totalCost <= maxTotalCost) " +
"AND (:startDate IS NULL OR o.orderDate >= startDate) " +
"AND (:endDate IS NULL OR o.orderDate <= endDate)")
Page<Order> findOrders(
@Param("status") String status,
@Param("customerId") Long customerId,
@Param("minTotalCost") Double minTotalCost,
@Param("maxTotalCost") Double maxTotalCost,
@Param("startDate") LocalDateTime startDate,
@Param("endDate") LocalDateTime endDate,
Pageable pageable
);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17
VisualStudioVersion = 17.0.31903.59
MinimumVisualStudioVersion = 10.0.40219.1
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "passwordValidator", "passwordValidator\passwordValidator.csproj", "{FFABDF22-C88D-4CF4-933A-BFE14C3264C5}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "passwordValidatorTest", "passwordValidatorTest\passwordValidatorTest.csproj", "{2908A07E-BBE3-49EB-9797-43859C4D7FF6}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{FFABDF22-C88D-4CF4-933A-BFE14C3264C5}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{FFABDF22-C88D-4CF4-933A-BFE14C3264C5}.Debug|Any CPU.Build.0 = Debug|Any CPU
{FFABDF22-C88D-4CF4-933A-BFE14C3264C5}.Release|Any CPU.ActiveCfg = Release|Any CPU
{FFABDF22-C88D-4CF4-933A-BFE14C3264C5}.Release|Any CPU.Build.0 = Release|Any CPU
{2908A07E-BBE3-49EB-9797-43859C4D7FF6}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{2908A07E-BBE3-49EB-9797-43859C4D7FF6}.Debug|Any CPU.Build.0 = Debug|Any CPU
{2908A07E-BBE3-49EB-9797-43859C4D7FF6}.Release|Any CPU.ActiveCfg = Release|Any CPU
{2908A07E-BBE3-49EB-9797-43859C4D7FF6}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
EndGlobal
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
using System.Text.RegularExpressions;


public class PasswordValidator
{
// Regular expression for a strong password
private static readonly string PASSWORD_REGEX =
@"^(?=.*[0-9])" +
@"(?=.*[a-z])" +
@"(?=.*[A-Z])" +
@"(?=*[@#$%^&+=])" +
@"(?=\S+$)" +
@".{10}";

private static readonly Regex PASSWORD_PATTERN = new Regex(PASSWORD_REGEX);

public static bool IsValidPassword(string password)
{
if (password == null)
{
return false;
}
Match match = PASSWORD_PATTERN.Match(password);
return match.Success;
}
}




Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
// See https://aka.ms/new-console-template for more information
Console.WriteLine("Hello, World!");
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net7.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>

</Project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net7.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>

<IsPackable>false</IsPackable>
<IsTestProject>true</IsTestProject>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="NUnit" Version="3.13.3" />
<PackageReference Include="NUnit3TestAdapter" Version="4.3.1" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.5.0" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\passwordValidator\passwordValidator.csproj" />
</ItemGroup>

</Project>
18 changes: 18 additions & 0 deletions code-bugfixing/password-validator/TypeScript/VSCode/jest.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
module.exports = {
"roots": [
"<rootDir>/src"
],
"transform": {
"^.+\\.tsx?$": "ts-jest"
},
"testRegex": "(/__tests__/.*|(\\.|/)(test|spec))\\.tsx?$",
"moduleFileExtensions": [
"ts",
"tsx",
"js",
"jsx",
"json",
"node"
],
}

Loading