Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
AntonioTrovato committed Mar 8, 2024
0 parents commit 7a55b5a
Show file tree
Hide file tree
Showing 20 changed files with 966 additions and 0 deletions.
2 changes: 2 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# Auto detect text files and perform LF normalization
* text=auto
42 changes: 42 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
.gradle
build/
!gradle/wrapper/gradle-wrapper.jar
!**/src/main/**/build/
!**/src/test/**/build/

### IntelliJ IDEA ###
.idea/modules.xml
.idea/jarRepositories.xml
.idea/compiler.xml
.idea/libraries/
*.iws
*.iml
*.ipr
out/
!**/src/main/**/out/
!**/src/test/**/out/

### Eclipse ###
.apt_generated
.classpath
.factorypath
.project
.settings
.springBeans
.sts4-cache
bin/
!**/src/main/**/bin/
!**/src/test/**/bin/

### NetBeans ###
/nbproject/private/
/nbbuild/
/dist/
/nbdist/
/.nb-gradle/

### VS Code ###
.vscode/

### Mac OS ###
.DS_Store
8 changes: 8 additions & 0 deletions .idea/.gitignore

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 16 additions & 0 deletions .idea/checkstyle-idea.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

19 changes: 19 additions & 0 deletions .idea/gradle.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 10 additions & 0 deletions .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

124 changes: 124 additions & 0 deletions .idea/uiDesigner.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

43 changes: 43 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
Using: java 17.0.10 e gradle 7.4.2

Build the ju2jmh tool (In the Tool Root):
gradle build

New Gradle Project using Kotling language
Make 2 subproject:
GradleProject
|--app (build.gradle.kts must have the right dependencies for junit 4.13.2)
|--src/main/java/(containing packages of classes)
|--src/test/java/(containing packages of test classes)
|--ju2jmh
|--src/jmh/java/(containing packages of benchmarks)
|--src/main/java/
|--src/test/java/

the ju2jmh/src/jmh/java and ju2jmh/src/jmh/resources folders must be created by hand, then run the build.gradle.kts (using id("me.champeau.jmh") version "0.6.6" as plugin and the needed dependencies)
packages must have the same name and be organized the same way for each module

build GradleProject (In the Target Project Root):
gradle build

remove existent benchmarks (In the Target Project Root):
rm -r ju2jmh/src/jmh/java/*

re-build GradleProject (In the Target Project Root):
gradle clean
gradle build

run generation
gradle converter:run --args="C:/Users/anton/Documents/IntellijProjects/GradleProject/app/src/test/java/ C:/Users/anton/Documents/IntellijProjects/GradleProject/app/build/classes/java/test/ C:/Users/anton/Documents/IntellijProjects/GradleProject/ju2jmh/src/jmh/java/ banca.ContoBancario"

build benchmarks (In the Target Project Root):
gradle jmhJar

list avaible benchmarks:
java -jar C:/Users/anton/Documents/IntellijProjects/GradleProject/ju2jmh/build/libs/ju2jmh-jmh.jar -l

run benchmarks (first way):
use the jmh task in the gradle menu under ju2jmh opening GradleProject with IntelliJ

run the benchmarks (second way):
java -jar C:/Users/anton/Documents/IntellijProjects/GradleProject/ju2jmh/build/libs/ju2jmh-jmh.jar -f 1 -wi 0 -i 1 -r 100ms -foe true
11 changes: 11 additions & 0 deletions app/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
plugins {
java
}

dependencies {
testImplementation("junit:junit:4.13.2")
}

tasks.named<Test>("test") {
useJUnit()
}
39 changes: 39 additions & 0 deletions app/src/main/java/banca/ContoBancario.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package banca;

public class ContoBancario {
public ContoBancario(String id, int saldo_iniziale) {
this.id = id;
this.saldo = saldo_iniziale;
}

public String getId() {
return id;
}

public int getSaldo() {
return saldo;
}

public void setId(String id) {
this.id = id;
}

public void setSaldo(int saldo) {
this.saldo = saldo;
}

public void versamento(int quota) {
this.saldo += quota;
}

public int prelievo(int quota) {
if (this.saldo < quota)
return 0;
else
this.saldo -= quota;
return 1;
}

private String id;
private int saldo;
}
57 changes: 57 additions & 0 deletions app/src/test/java/banca/ContoBancarioTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
package banca;

import banca.ContoBancario;
import org.junit.Test;
import static org.junit.Assert.*;

public class ContoBancarioTest {

@Test
public void testVersamento() {
ContoBancario conto = new ContoBancario("123", 100);
conto.versamento(50);
assertEquals(150, conto.getSaldo());
}

@Test
public void testPrelievo_SufficienteSaldo() {
ContoBancario conto = new ContoBancario("123", 100);
int result = conto.prelievo(50);
assertEquals(1, result);
assertEquals(50, conto.getSaldo());
}

@Test
public void testPrelievo_InsufficienteSaldo() {
ContoBancario conto = new ContoBancario("123", 100);
int result = conto.prelievo(150);
assertEquals(0, result);
assertEquals(100, conto.getSaldo());
}

@Test
public void testGetId() {
ContoBancario conto = new ContoBancario("123", 100);
assertEquals("123", conto.getId());
}

@Test
public void testSetId() {
ContoBancario conto = new ContoBancario("123", 100);
conto.setId("456");
assertEquals("456", conto.getId());
}

@Test
public void testGetSaldo() {
ContoBancario conto = new ContoBancario("123", 100);
assertEquals(100, conto.getSaldo());
}

@Test
public void testSetSaldo() {
ContoBancario conto = new ContoBancario("123", 100);
conto.setSaldo(200);
assertEquals(200, conto.getSaldo());
}
}
Loading

0 comments on commit 7a55b5a

Please sign in to comment.