Skip to content
Open
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
38 changes: 38 additions & 0 deletions java-intro-testing/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
target/
!.mvn/wrapper/maven-wrapper.jar
!**/src/main/**/target/
!**/src/test/**/target/

### IntelliJ IDEA ###
.idea/modules.xml
.idea/jarRepositories.xml
.idea/compiler.xml
.idea/libraries/
*.iws
*.iml
*.ipr

### Eclipse ###
.apt_generated
.classpath
.factorypath
.project
.settings
.springBeans
.sts4-cache

### NetBeans ###
/nbproject/private/
/nbbuild/
/dist/
/nbdist/
/.nb-gradle/
build/
!**/src/main/**/build/
!**/src/test/**/build/

### VS Code ###
.vscode/

### Mac OS ###
.DS_Store
3 changes: 3 additions & 0 deletions java-intro-testing/.idea/.gitignore

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

7 changes: 7 additions & 0 deletions java-intro-testing/.idea/encodings.xml

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

14 changes: 14 additions & 0 deletions java-intro-testing/.idea/misc.xml

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

6 changes: 6 additions & 0 deletions java-intro-testing/.idea/vcs.xml

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

File renamed without changes.
31 changes: 31 additions & 0 deletions java-intro-testing/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<?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>org.example</groupId>
<artifactId>java-intro-testing</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</artifactId>
<version>RELEASE</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter</artifactId>
<version>RELEASE</version>
<scope>test</scope>
</dependency>
</dependencies>

</project>
33 changes: 33 additions & 0 deletions java-intro-testing/src/main/java/org/example/Main.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package org.example;

public class Main {
public static void main(String[] args) {


}

public int[] myFirstTestedMethod(int num){
int longitudArray = (num+1)/2;
int [] arrayNums = new int[longitudArray];;
int index = 1;

for(int i = 0;index <= num;i++){
arrayNums[i] = index;
index = index+2;
}
return arrayNums;
}

public boolean stringToBoolean(String string){
String[] listOfKeywords = {"abstract","continue","for","new","switch","assert","default","goto","package","synchronized","boolean","do","if","private","this","break","double","implements","protected","throw","byte","else","import","public","throws","case","enum","instanceof","return","transient","catch","extends","int","short","try","char","final","interface","static","void","class","finally","long","strictfp","volatile","const","float","native","super","while"};
String[] wordsFromString = string.split(" ");;
for(int i=0;i<=listOfKeywords.length-1;i++){
for(int j=0;j<=wordsFromString.length-1;j++){
if(listOfKeywords[i].equals(wordsFromString[j])){
return true;
}
}
}
return false;
}
}
37 changes: 37 additions & 0 deletions java-intro-testing/src/main/java/org/example/PlayerClass/Elf.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package org.example.PlayerClass;

public class Elf extends Player{
private int speed;
final private int initialHealth;
public Elf(int health, int strength, int lives, int speed) {
super(health, strength, lives);
setSpeed(speed);
initialHealth = health;
}

public int getSpeed() {
return speed;
}

public void setSpeed(int speed) {
this.speed = speed;
}

public void decrementLive() {
setHealth(initialHealth);
super.setLives(super.getLives()-1);
if(getLives()<=0){
System.out.println("This character is dead");
}
}

public void attack(Player playerToAttack) {
playerToAttack.setHealth(playerToAttack.getHealth()-getStrength());
}

public void checkHealth() {
if(getHealth()<=0){
decrementLive();
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
package org.example.PlayerClass;

abstract public class Player {
private int health;
private int strength;
private int lives;

public Player(int health, int strength, int lives) {
setHealth(health);
setStrength(strength);
setLives(lives);
}

public int getHealth() {
return health;
}

public void setHealth(int health) {
this.health = health;
}

public int getStrength() {
return strength;
}

public void setStrength(int strength) {
this.strength = strength;
}

public int getLives() {
return lives;
}

public void setLives(int lives) {
this.lives = lives;
}

abstract public void decrementLive();

abstract public void attack(Player playerToAttack);

abstract public void checkHealth();

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
package org.example.PlayerClass;

public class Warrior extends Player {
private int force;
final private int initialHealth;

public Warrior(int health, int strength, int lives, int force) {
super(health, strength, lives);
setForce(force);
initialHealth = health;
}

public int getForce() {
return force;
}

public void setForce(int force) {
this.force = force;
}

public void decrementLive() {
setHealth(initialHealth);
super.setLives(super.getLives() - 1);
if (getLives() <= 0) {
System.out.println("This character is dead");
}
}

public void attack(Player playerToAttack) {
playerToAttack.setHealth(playerToAttack.getHealth() - getStrength());
}

public void checkHealth() {
if(getHealth()<=0){
decrementLive();
}
}

public Elf convertToElf () {
Elf elf = new Elf(getHealth(), getStrength(), getLives(), getForce());
return elf;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
package org.example.PlayerClass;

public class Wizard extends Player {
private int spell;
final private int initialHealth;
public Wizard(int health, int strength, int lives, int spell) {
super(health, strength, lives);
setSpell(spell);
initialHealth = health;
}

public int getSpell() {
return spell;
}

public void setSpell(int spell) {
this.spell = spell;
}

public void decrementLive() {
setHealth(initialHealth);
super.setLives(super.getLives()-1);
if(getLives()<=0){
System.out.println("This character is dead");
}
}

public void attack(Player playerToAttack) {
playerToAttack.setHealth(playerToAttack.getHealth()-getStrength());
}

public void checkHealth() {
if(getHealth()<=0){
decrementLive();
}
}

public Elf convertToElf(){
Elf elf = new Elf(getHealth(),getStrength(),getLives(),getSpell());
return elf;
}
}
26 changes: 26 additions & 0 deletions java-intro-testing/src/test/java/org/example/MainTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package org.example;

import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.*;

class MainTest {


@Test
void testMyFirstTDD() {
Main my = new Main();
int num = 10;
int[] oddNumbers = my.myFirstTestedMethod(num);
int[] oddResult = {1,3,5,7,9};
assertArrayEquals(oddResult, oddNumbers);
}

@Test
void stringToBoolean() {
String string = "Hola este es un test";
Main my = new Main();
boolean result = my.stringToBoolean(string);
assertEquals(false,result);

}
}
Loading