progtech exam

This commit is contained in:
anon 2024-06-07 11:46:13 +02:00
parent 1f0f412eee
commit 5141ce8dc1
33 changed files with 1080 additions and 0 deletions
Java/jumpin
.unittest
my-app
pom.xml
src
main/java/com/mycompany/app
test/java/com/mycompany/app
pom.xml
src
target
maven-status/maven-compiler-plugin
compile/default-compile
testCompile/default-testCompile
surefire-reports
clean
my-app
pom.xml
src
main/java/com/mycompany/app
test/java/com/mycompany/app
pom.xml
src
target
maven-status/maven-compiler-plugin
compile/default-compile
testCompile/default-testCompile
surefire-reports
txt.txt

@ -0,0 +1,18 @@
<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>com.mycompany.app</groupId>
<artifactId>my-app</artifactId>
<packaging>jar</packaging>
<version>1.0-SNAPSHOT</version>
<name>my-app</name>
<url>http://maven.apache.org</url>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<scope>test</scope>
</dependency>
</dependencies>
</project>

@ -0,0 +1,13 @@
package com.mycompany.app;
/**
* Hello world!
*
*/
public class App
{
public static void main( String[] args )
{
System.out.println( "Hello World!" );
}
}

@ -0,0 +1,38 @@
package com.mycompany.app;
import junit.framework.Test;
import junit.framework.TestCase;
import junit.framework.TestSuite;
/**
* Unit test for simple App.
*/
public class AppTest
extends TestCase
{
/**
* Create the test case
*
* @param testName name of the test case
*/
public AppTest( String testName )
{
super( testName );
}
/**
* @return the suite of tests being tested
*/
public static Test suite()
{
return new TestSuite( AppTest.class );
}
/**
* Rigourous Test :-)
*/
public void testApp()
{
assertTrue( true );
}
}

@ -0,0 +1,24 @@
<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.example</groupId>
<artifactId>my-maven-project</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>jar</packaging>
<name>My Maven Project</name>
<url>http://maven.apache.org</url>
<!-- Add the JUnit dependency -->
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.13.2</version>
<scope>test</scope>
</dependency>
</dependencies>
</project>

@ -0,0 +1,5 @@
public class MyClass {
public int add(int a, int b) {
return a + b;
}
}

@ -0,0 +1,13 @@
// @BAKE java MyClassTest.java
import org.junit.Test;
import static org.junit.Assert.assertEquals;
public class MyClassTest {
@Test
public void testAdd() {
MyClass myClass = new MyClass();
int result = myClass.add(2, 3);
assertEquals("Sum should be 5", 5, result);
}
}

@ -0,0 +1 @@
/home/anon/Swap/school/patterns/jumpin/unittest/src/main/java/MyClass.java

@ -0,0 +1 @@
/home/anon/Swap/school/patterns/jumpin/unittest/src/test/java/MyClassTest.java

@ -0,0 +1,4 @@
-------------------------------------------------------------------------------
Test set: MyClassTest
-------------------------------------------------------------------------------
Tests run: 1, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.046 s -- in MyClassTest

@ -0,0 +1,58 @@
<?xml version="1.0" encoding="UTF-8"?>
<testsuite xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="https://maven.apache.org/surefire/maven-surefire-plugin/xsd/surefire-test-report-3.0.xsd" version="3.0" name="MyClassTest" time="0.046" tests="1" errors="0" skipped="0" failures="0">
<properties>
<property name="java.specification.version" value="21"/>
<property name="sun.jnu.encoding" value="UTF-8"/>
<property name="java.class.path" value="/home/anon/Swap/school/patterns/jumpin/unittest/target/test-classes:/home/anon/Swap/school/patterns/jumpin/unittest/target/classes:/home/anon/.m2/repository/junit/junit/4.13.2/junit-4.13.2.jar:/home/anon/.m2/repository/org/hamcrest/hamcrest-core/1.3/hamcrest-core-1.3.jar:"/>
<property name="java.vm.vendor" value="Eclipse Adoptium"/>
<property name="sun.arch.data.model" value="64"/>
<property name="java.vendor.url" value="https://adoptium.net/"/>
<property name="os.name" value="Linux"/>
<property name="java.vm.specification.version" value="21"/>
<property name="sun.java.launcher" value="SUN_STANDARD"/>
<property name="user.country" value="US"/>
<property name="sun.boot.library.path" value="/opt/openjdk-bin-21.0.3_p9/lib"/>
<property name="sun.java.command" value="/home/anon/Swap/school/patterns/jumpin/unittest/target/surefire/surefirebooter-20240606115358555_3.jar /home/anon/Swap/school/patterns/jumpin/unittest/target/surefire 2024-06-06T11-53-57_715-jvmRun1 surefire-20240606115358555_1tmp surefire_0-20240606115358555_2tmp"/>
<property name="jdk.debug" value="release"/>
<property name="surefire.test.class.path" value="/home/anon/Swap/school/patterns/jumpin/unittest/target/test-classes:/home/anon/Swap/school/patterns/jumpin/unittest/target/classes:/home/anon/.m2/repository/junit/junit/4.13.2/junit-4.13.2.jar:/home/anon/.m2/repository/org/hamcrest/hamcrest-core/1.3/hamcrest-core-1.3.jar:"/>
<property name="sun.cpu.endian" value="little"/>
<property name="user.home" value="/home/anon"/>
<property name="user.language" value="en"/>
<property name="java.specification.vendor" value="Oracle Corporation"/>
<property name="java.version.date" value="2024-04-16"/>
<property name="java.home" value="/opt/openjdk-bin-21.0.3_p9"/>
<property name="file.separator" value="/"/>
<property name="basedir" value="/home/anon/Swap/school/patterns/jumpin/unittest"/>
<property name="java.vm.compressedOopsMode" value="32-bit"/>
<property name="line.separator" value="&#10;"/>
<property name="java.specification.name" value="Java Platform API Specification"/>
<property name="java.vm.specification.vendor" value="Oracle Corporation"/>
<property name="surefire.real.class.path" value="/home/anon/Swap/school/patterns/jumpin/unittest/target/surefire/surefirebooter-20240606115358555_3.jar"/>
<property name="sun.management.compiler" value="HotSpot 64-Bit Tiered Compilers"/>
<property name="java.runtime.version" value="21.0.3+9-LTS"/>
<property name="user.name" value="anon"/>
<property name="stdout.encoding" value="UTF-8"/>
<property name="path.separator" value=":"/>
<property name="os.version" value="6.7.2-gentoo-r1"/>
<property name="java.runtime.name" value="OpenJDK Runtime Environment"/>
<property name="file.encoding" value="UTF-8"/>
<property name="java.vm.name" value="OpenJDK 64-Bit Server VM"/>
<property name="java.vendor.version" value="Temurin-21.0.3+9"/>
<property name="localRepository" value="/home/anon/.m2/repository"/>
<property name="java.vendor.url.bug" value="https://github.com/adoptium/adoptium-support/issues"/>
<property name="java.io.tmpdir" value="/tmp"/>
<property name="java.version" value="21.0.3"/>
<property name="user.dir" value="/home/anon/Swap/school/patterns/jumpin/unittest"/>
<property name="os.arch" value="amd64"/>
<property name="java.vm.specification.name" value="Java Virtual Machine Specification"/>
<property name="native.encoding" value="UTF-8"/>
<property name="java.library.path" value="/usr/java/packages/lib:/usr/lib64:/lib64:/lib:/usr/lib"/>
<property name="java.vm.info" value="mixed mode, sharing"/>
<property name="stderr.encoding" value="UTF-8"/>
<property name="java.vendor" value="Eclipse Adoptium"/>
<property name="java.vm.version" value="21.0.3+9-LTS"/>
<property name="sun.io.unicode.encoding" value="UnicodeLittle"/>
<property name="java.class.version" value="65.0"/>
</properties>
<testcase name="testAdd" classname="MyClassTest" time="0.003"/>
</testsuite>

3
Java/jumpin/clean Executable file

@ -0,0 +1,3 @@
#!/bin/bash
rm *.class

@ -0,0 +1,18 @@
<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>com.mycompany.app</groupId>
<artifactId>my-app</artifactId>
<packaging>jar</packaging>
<version>1.0-SNAPSHOT</version>
<name>my-app</name>
<url>http://maven.apache.org</url>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<scope>test</scope>
</dependency>
</dependencies>
</project>

@ -0,0 +1,13 @@
package com.mycompany.app;
/**
* Hello world!
*
*/
public class App
{
public static void main( String[] args )
{
System.out.println( "Hello World!" );
}
}

@ -0,0 +1,38 @@
package com.mycompany.app;
import junit.framework.Test;
import junit.framework.TestCase;
import junit.framework.TestSuite;
/**
* Unit test for simple App.
*/
public class AppTest
extends TestCase
{
/**
* Create the test case
*
* @param testName name of the test case
*/
public AppTest( String testName )
{
super( testName );
}
/**
* @return the suite of tests being tested
*/
public static Test suite()
{
return new TestSuite( AppTest.class );
}
/**
* Rigourous Test :-)
*/
public void testApp()
{
assertTrue( true );
}
}

23
Java/jumpin/pom.xml Normal file

@ -0,0 +1,23 @@
<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.example</groupId>
<artifactId>my-maven-project</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>jar</packaging>
<name>My Maven Project</name>
<url>http://maven.apache.org</url>
<!-- Add the JUnit dependency -->
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.13.2</version>
<scope>test</scope>
</dependency>
</dependencies>
</project>

@ -0,0 +1,131 @@
// @BAKE javac -Xlint *.java
import java.util.*;
//public class Main {
// public static void main(String[] args) {
// return;
// }
//}
//public class Main {
// public static void main(String[] args) {
// Market m = new Market();
// }
//}
//public class Main {
// public static void main(String[] args) {
// Market m = new Market();
// boolean r = m.buyFrom(0, "apple", 100, 1.0);
// }
//}
//public class Main {
// public static void main(String[] args) {
// int prefered_buy_price = 100;
// double prefered_buy_amount = 1.0;
// String prefered_buy_subject = "apple";
//
// Market m = new Market();
// boolean buy_success = m.buyFrom(0, prefered_buy_subject, prefered_buy_price, prefered_buy_amount);
// if (buy_success) {
// System.out.println("Successfully bought "
// + prefered_buy_amount + " kg "
// + prefered_buy_subject + "s for "
// + prefered_buy_price);
// } else {
// System.out.println("Buying failed.");
// }
// }
//}
//public class Main {
// public static void main(String[] args) {
// int prefered_buy_price = 100;
// double prefered_buy_amount = 10.5;
// String prefered_buy_subject = "apple";
//
// Market m = new Market();
// boolean buy_success = m.buyFrom(0, prefered_buy_subject, prefered_buy_price, prefered_buy_amount);
// if (buy_success) {
// System.out.println("Successfully bought "
// + prefered_buy_amount + " kg "
// + prefered_buy_subject + "s for "
// + prefered_buy_price);
// } else {
// System.out.println("Buying failed.");
// }
// }
//}
//public class Main {
// public static void main(String[] args) {
// int prefered_buy_price = 100;
// double prefered_buy_amount = 5.2;
// String prefered_buy_subject = "apple";
//
// Market m = new Market();
// boolean buy_success = m.buyFrom(0, prefered_buy_subject, prefered_buy_price, prefered_buy_amount);
// if (buy_success) {
// System.out.println("Successfully bought "
// + prefered_buy_amount + " kg "
// + prefered_buy_subject + "s for "
// + prefered_buy_price);
// } else {
// System.out.println("Buying failed.");
// }
// }
//}
//public class Main {
// public static void main(String[] args) {
// int prefered_buy_price = 100;
// double prefered_buy_amount = 5.2;
// String prefered_buy_subject = "apple";
//
// Market nagybaniPiac = new Market();
// boolean buy_success = nagybaniPiac.buyFrom(0, prefered_buy_subject, prefered_buy_price, prefered_buy_amount);
// if (buy_success) {
// System.out.println("Successfully bought "
// + prefered_buy_amount + " kg "
// + prefered_buy_subject + "s for "
// + prefered_buy_price);
// } else {
// System.out.println("Buying failed.");
// }
// }
//}
public class Main {
public static void main(String[] args) {
Random randy = new Random();
int prefered_buy_price = 100;
double prefered_buy_amount = 5.2;
String prefered_buy_subject = "apple";
Market nagybaniPiac = new Market();
int c = nagybaniPiac.getSellerCount();
if (c == 0) {
System.out.println("The market is empty.");
return;
}
int sellerIndex = randy.nextInt(c);
boolean buy_success = nagybaniPiac.buyFrom(sellerIndex,
prefered_buy_subject,
prefered_buy_price,
prefered_buy_amount
);
if (buy_success) {
System.out.println("Successfully bought "
+ prefered_buy_amount + " kg "
+ prefered_buy_subject + "s for "
+ prefered_buy_price);
} else {
System.out.println("Buying failed.");
}
}
}

@ -0,0 +1,195 @@
import java.util.*;
//public class Market {
// List<Seller> sellers = new ArrayList<>();
//
// public Market() {
// sellers.add(new Seller());
// }
//}
//public class Market {
// List<Seller> sellers = new ArrayList<>();
//
// public Market() {
// sellers.add(new Seller());
// }
//
// public boolean buyFrom(int seller, String what, int for_price, double amount) {
// int i = sellers.get(seller).buy(what, for_price, amount);
// return true;
// }
//}
//public class Market {
// List<Seller> sellers = new ArrayList<>();
//
// public Market() {
// sellers.add(new Seller());
// }
//
// public boolean buyFrom(int seller, String what, int for_price, double amount) {
// int i = sellers.get(seller).buy(what, for_price, amount);
// if (for_price >= i) {
// return true;
// } else {
// return false;
// }
// }
//}
//public class Market {
// List<Seller> sellers = new ArrayList<>();
//
// public Market() {
// SellerFactory f = new SellerFactory();
// HashMap<String, Integer> m = new HashMap();
//
// m.put("apple", 15);
// m.put("pear", 20);
//
// for (int i = 0; i < 10; i++) {
// try {
// sellers.add(f.makeSeller(m));
// } catch (Exception e) {
// System.out.println("Making a seller went wrong");
// }
// }
// }
//
// public boolean buyFrom(int seller, String what, int for_price, double amount) {
// int i = sellers.get(seller).buy(what, for_price, amount);
// if (for_price >= i) {
// return true;
// } else {
// return false;
// }
// }
//}
//public class Market {
// List<Seller> sellers = new ArrayList<>();
//
// public Market() {
// SellerFactory f = new SellerFactory();
// Random rand = new Random();
//
// try {
// for (int i = 0; i < 3; i++) {
// HashMap<String, Integer> m = new HashMap<String, Integer>();
// m.put("apple", rand.nextInt(21) + 10);
// m.put("pear", rand.nextInt(21) + 10);
// sellers.add(f.makeSeller(m));
// }
//
// if (true) {
// HashMap<String, Integer> m = new HashMap<String, Integer>();
//
// m.put("apple", rand.nextInt(11) + 10);
// m.put("pear", rand.nextInt(11) + 10);
// sellers.add(f.makeSeller(m, "greedy"));
//
// m.put("apple", rand.nextInt(25) + 10);
// m.put("pear", rand.nextInt(25) + 10);
// sellers.add(f.makeSeller(m, "compromizing"));
// }
// } catch (Exception e) {
// System.out.println("Making a seller went wrong");
// }
// }
//
// public boolean buyFrom(int seller, String what, int for_price, double amount) {
// int i = sellers.get(seller).buy(what, for_price, amount);
// if (for_price >= i) {
// return true;
// } else {
// return false;
// }
// }
//}
//public class Market {
// private List<Seller> sellers = new ArrayList<>();
//
// public Market() {
// SellerFactory f = new SellerFactory();
// Random rand = new Random();
//
// try {
// for (int i = 0; i < 3; i++) {
// HashMap<String, Integer> m = new HashMap<String, Integer>();
// m.put("apple", rand.nextInt(21) + 10);
// m.put("pear", rand.nextInt(21) + 10);
// sellers.add(f.makeSeller(m));
// }
//
// if (true) {
// HashMap<String, Integer> m = new HashMap<String, Integer>();
//
// m.put("apple", rand.nextInt(11) + 10);
// m.put("pear", rand.nextInt(11) + 10);
// sellers.add(f.makeSeller(m, "greedy"));
//
// m.put("apple", rand.nextInt(25) + 10);
// m.put("pear", rand.nextInt(25) + 10);
// sellers.add(f.makeSeller(m, "compromizing"));
// }
// } catch (Exception e) {
// System.out.println("Making a seller went wrong");
// }
// }
//
// public int getSellerCount() {
// return 0;
// }
//
// public boolean buyFrom(int seller, String what, int for_price, double amount) {
// int i = sellers.get(seller).buy(what, for_price, amount);
// if (for_price >= i) {
// return true;
// } else {
// return false;
// }
// }
//}
public class Market {
private List<Seller> sellers = new ArrayList<>();
public Market() {
SellerFactory f = new SellerFactory();
Random randy = new Random();
try {
for (int i = 0; i < 3; i++) {
HashMap<String, Integer> m = new HashMap<String, Integer>();
m.put("apple", randy.nextInt(21) + 10);
m.put("pear", randy.nextInt(21) + 10);
sellers.add(f.makeSeller(m));
}
if (true) {
HashMap<String, Integer> m = new HashMap<String, Integer>();
m.put("apple", randy.nextInt(11) + 10);
m.put("pear", randy.nextInt(11) + 10);
sellers.add(f.makeSeller(m, "greedy"));
m.put("apple", randy.nextInt(25) + 10);
m.put("pear", randy.nextInt(25) + 10);
sellers.add(f.makeSeller(m, "compromizing"));
}
} catch (Exception e) {
System.out.println("Making a seller went wrong");
}
}
public int getSellerCount() {
return sellers.size();
}
public boolean buyFrom(int seller, String what, int for_price, double amount) {
int i = sellers.get(seller).buy(what, for_price, amount);
return for_price >= i;
}
}

@ -0,0 +1,141 @@
import java.util.*;
//public class Seller {
// public int buy(String what, int for_price, float amount) {
// return 0;
// }
//}
//public class Seller {
// public int buy(String what, int for_price, double amount) {
// return 0;
// }
//}
//public class Seller {
// HashMap<String, Integer> price_table = new HashMap<>();
//
// public Seller() {
// price_table.put("apple", 15);
// price_table.put("pear", 20);
// }
//
// public int buy(String what, int for_price, double amount) {
// int p = price_table.get(what);
// return (int)(p * amount);
// }
//}
//public class Seller {
// HashMap<String, Integer> price_table = new HashMap<>();
// SellerStrategy strategy = new SellerStrategy();
//
// public Seller() {
// price_table.put("apple", 15);
// price_table.put("pear", 20);
// }
//
// public int buy(String what, int for_price, double amount) {
// int p = price_table.get(what);
// return (int)(p * amount);
// }
//}
//public class Seller {
// HashMap<String, Integer> price_table = new HashMap<>();
// SellerStrategy strategy = new SellerStrategy();
//
// public Seller() {
// price_table.put("apple", 15);
// price_table.put("pear", 20);
// }
//
// public int buy(String what, int for_price, double amount) {
// int p = price_table.get(what);
// return strategy((int)(p * amount), for_price);
// }
//}
//public class Seller {
// HashMap<String, Integer> price_table = new HashMap<>();
// SellerStrategy strategy = new Strategy1();
//
// public Seller() {
// price_table.put("apple", 15);
// price_table.put("pear", 20);
// }
//
// public int buy(String what, int for_price, double amount) {
// int p = price_table.get(what);
// return strategy((int)(p * amount), for_price);
// }
//}
//public class Seller {
// HashMap<String, Integer> price_table = new HashMap<>();
// SellerStrategy strategy;
//
// public Seller(SellerStrategy strategy_) {
// strategy = strategy_;
// price_table.put("apple", 15);
// price_table.put("pear", 20);
// }
//
// public int buy(String what, int for_price, double amount) {
// int p = price_table.get(what);
// return strategy.strategize((int)(p * amount), for_price);
// }
//}
//public class Seller {
// HashMap<String, Integer> priceTable = new HashMap<>();
// SellerStrategy strategy;
//
// public Seller(SellerStrategy strategy_, HashMap priceTable_) throws IllegalArgumentException {
// if (priceTable == null) {
// throw new IllegalArgumentException("Table cannot be null.");
// }
// strategy = strategy_;
// priceTable = priceTable_;
// }
//
// public int buy(String what, int for_price, double amount) throws IllegalArgumentException {
// Integer p = priceTable.get(what);
// if (p == null) {
// throw new IllegalArgumentException("No such item for sale.");
// }
// return strategy.strategize((int)(p * amount), for_price);
// }
//}
public class Seller {
HashMap<String, Integer> priceTable;
SellerStrategy strategy;
public Seller() {
strategy = new StrategySimple();
priceTable = new HashMap<String, Integer>();
priceTable.put("apple", 15);
priceTable.put("pear", 20);
}
public Seller(SellerStrategy strategy_, HashMap<String, Integer> priceTable_) throws IllegalArgumentException {
if (strategy_ == null) {
throw new IllegalArgumentException("Strategy must not be null");
}
strategy = strategy_;
if (priceTable_ == null) {
throw new IllegalArgumentException("Table cannot be null.");
}
priceTable = priceTable_;
}
public int buy(String what, int for_price, double amount) throws IllegalArgumentException {
Integer p = priceTable.get(what);
if (p == null) {
throw new IllegalArgumentException("No such item for sale.");
}
return strategy.strategize((int)(p * amount), for_price);
}
}

@ -0,0 +1,52 @@
import java.util.*;
//public class SellerFactory {
// Seller makeSeller() {
// return new Seller();
// }
//}
//public class SellerFactory {
// Seller makeSeller() {
// return new Seller(new Strategy1());
// }
//
// Seller makeSeller(String type) {
// return new Seller(new Strategy1());
// }
//}
//public class SellerFactory {
// Seller makeSeller() {
// return new Seller(new Strategy1());
// }
//
// Seller makeSeller(String type) {
// if (type == "compromizing") {
// return new Seller(new Strategy2());
// } else if (type == "greedy") {
// return new Seller(new Strategy3());
// }
// return new Seller(new Strategy1());
// }
//}
public class SellerFactory {
Seller makeSeller(HashMap<String, Integer> priceTable_) {
return new Seller(new StrategySimple(), priceTable_);
}
Seller makeSeller(HashMap<String, Integer> priceTable_, String type) {
if (priceTable_ == null) {
priceTable_ = new HashMap<String, Integer>();
}
if (type == "compromizing") {
return new Seller(new StrategyCompromizing(), priceTable_);
} else if (type == "greedy") {
return new Seller(new StrategyGreedy(), priceTable_);
}
return new Seller(new StrategySimple(), priceTable_);
}
}

@ -0,0 +1,9 @@
//public class SellerStrategy {
// public int strategize(int prefered, int actual) {
// return prefered;
// }
//}
public abstract class SellerStrategy {
public abstract int strategize(int prefered, int actual);
}

@ -0,0 +1,6 @@
public class StrategyCompromizing extends SellerStrategy {
@Override
public int strategize(int prefered, int actual) {
return (prefered + actual) / 2;
}
}

@ -0,0 +1,13 @@
//public class Strategy3 extends SellerStrategy {
// @Override
// public int strategize(int prefered, int actual) {
// return prefered * 2;
// }
//}
public class StrategyGreedy extends SellerStrategy {
@Override
public int strategize(int prefered, int actual) {
return prefered * 2;
}
}

@ -0,0 +1,6 @@
public class StrategySimple extends SellerStrategy {
@Override
public int strategize(int prefered, int actual) {
return prefered;
}
}

@ -0,0 +1,108 @@
import java.util.*;
import org.junit.Test;
import static org.junit.Assert.*;
public class MarketTests {
@Test
public void testTest() {
return;
}
@Test
public void newSellers() throws Exception {
Seller s;
s = new Seller();
HashMap<String, Integer> m = new HashMap<String, Integer>();
m.put("apple", 15);
m.put("pear", 20);
s = new Seller(new StrategyGreedy(), m);
s = new Seller(new StrategyCompromizing(), m);
}
@Test
public void invalidSeller() {
HashMap<String, Integer> m = new HashMap<String, Integer>();
try {
Seller s = new Seller(null, m);
fail("Invalid seller can be created.");
} catch (Exception e) {
// ;
}
try {
Seller s = new Seller(new StrategySimple(), null);
fail("Invalid seller can be created.");
} catch (Exception e) {
// ;
}
try {
Seller s = new Seller(null, null);
fail("Invalid seller can be created.");
} catch (Exception e) {
// ;
}
}
@Test
public void newMarget() {
Market m = new Market();
assertNotNull(m);
}
@Test
public void newBasicBuy() throws Exception {
Market m = new Market();
boolean r = m.buyFrom(0, "apple", 100, 1.0);
}
@Test
public void invalidSellerSelected() {
Market m = new Market();
try {
boolean r = m.buyFrom(-1, "apple", 100, 1.0);
fail("Did not throw on invalid index!");
} catch (Exception e) {
return;
}
}
@Test
public void mustSellSimple() {
HashMap<String, Integer> m = new HashMap<String, Integer>();
m.put("apple", 10);
Seller s = new Seller(new StrategySimple(), m);
assertTrue(s.buy("apple", 100, 1.0) <= 100);
}
@Test
public void mustNotSellGreedy() {
HashMap<String, Integer> m = new HashMap<String, Integer>();
m.put("apple", 10);
Seller s = new Seller(new StrategyGreedy(), m);
assertFalse(s.buy("apple", 10, 1.0) <= 10);
}
@Test
public void mustNotSellCompromizing() {
HashMap<String, Integer> m = new HashMap<String, Integer>();
m.put("apple", 10);
Seller s = new Seller(new StrategyCompromizing(), m);
assertFalse(s.buy("apple", 10, 1.0) < 10);
}
@Test
public void SellerFactoryMethod() {
SellerFactory f = new SellerFactory();
Seller s = f.makeSeller(null, "");
assertTrue(s instanceof Seller);
}
}

@ -0,0 +1,8 @@
Main.class
StrategyCompromizing.class
Market.class
SellerStrategy.class
Seller.class
StrategySimple.class
StrategyGreedy.class
SellerFactory.class

@ -0,0 +1,8 @@
/home/anon/Swap/school/patterns/jumpin/src/main/java/SellerStrategy.java
/home/anon/Swap/school/patterns/jumpin/src/main/java/StrategyCompromizing.java
/home/anon/Swap/school/patterns/jumpin/src/main/java/StrategyGreedy.java
/home/anon/Swap/school/patterns/jumpin/src/main/java/StrategySimple.java
/home/anon/Swap/school/patterns/jumpin/src/main/java/SellerFactory.java
/home/anon/Swap/school/patterns/jumpin/src/main/java/Seller.java
/home/anon/Swap/school/patterns/jumpin/src/main/java/Market.java
/home/anon/Swap/school/patterns/jumpin/src/main/java/Main.java

@ -0,0 +1 @@
/home/anon/Swap/school/patterns/jumpin/src/test/java/MarketTests.java

@ -0,0 +1,4 @@
-------------------------------------------------------------------------------
Test set: MarketTests
-------------------------------------------------------------------------------
Tests run: 10, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.071 s -- in MarketTests

@ -0,0 +1,67 @@
<?xml version="1.0" encoding="UTF-8"?>
<testsuite xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="https://maven.apache.org/surefire/maven-surefire-plugin/xsd/surefire-test-report-3.0.xsd" version="3.0" name="MarketTests" time="0.071" tests="10" errors="0" skipped="0" failures="0">
<properties>
<property name="java.specification.version" value="21"/>
<property name="sun.jnu.encoding" value="UTF-8"/>
<property name="java.class.path" value="/home/anon/Swap/school/patterns/jumpin/target/test-classes:/home/anon/Swap/school/patterns/jumpin/target/classes:/home/anon/.m2/repository/junit/junit/4.13.2/junit-4.13.2.jar:/home/anon/.m2/repository/org/hamcrest/hamcrest-core/1.3/hamcrest-core-1.3.jar:"/>
<property name="java.vm.vendor" value="Eclipse Adoptium"/>
<property name="sun.arch.data.model" value="64"/>
<property name="java.vendor.url" value="https://adoptium.net/"/>
<property name="os.name" value="Linux"/>
<property name="java.vm.specification.version" value="21"/>
<property name="sun.java.launcher" value="SUN_STANDARD"/>
<property name="user.country" value="US"/>
<property name="sun.boot.library.path" value="/opt/openjdk-bin-21.0.3_p9/lib"/>
<property name="sun.java.command" value="/home/anon/Swap/school/patterns/jumpin/target/surefire/surefirebooter-20240606133534982_3.jar /home/anon/Swap/school/patterns/jumpin/target/surefire 2024-06-06T13-35-34_876-jvmRun1 surefire-20240606133534982_1tmp surefire_0-20240606133534982_2tmp"/>
<property name="jdk.debug" value="release"/>
<property name="surefire.test.class.path" value="/home/anon/Swap/school/patterns/jumpin/target/test-classes:/home/anon/Swap/school/patterns/jumpin/target/classes:/home/anon/.m2/repository/junit/junit/4.13.2/junit-4.13.2.jar:/home/anon/.m2/repository/org/hamcrest/hamcrest-core/1.3/hamcrest-core-1.3.jar:"/>
<property name="sun.cpu.endian" value="little"/>
<property name="user.home" value="/home/anon"/>
<property name="user.language" value="en"/>
<property name="java.specification.vendor" value="Oracle Corporation"/>
<property name="java.version.date" value="2024-04-16"/>
<property name="java.home" value="/opt/openjdk-bin-21.0.3_p9"/>
<property name="file.separator" value="/"/>
<property name="basedir" value="/home/anon/Swap/school/patterns/jumpin"/>
<property name="java.vm.compressedOopsMode" value="32-bit"/>
<property name="line.separator" value="&#10;"/>
<property name="java.specification.name" value="Java Platform API Specification"/>
<property name="java.vm.specification.vendor" value="Oracle Corporation"/>
<property name="surefire.real.class.path" value="/home/anon/Swap/school/patterns/jumpin/target/surefire/surefirebooter-20240606133534982_3.jar"/>
<property name="sun.management.compiler" value="HotSpot 64-Bit Tiered Compilers"/>
<property name="java.runtime.version" value="21.0.3+9-LTS"/>
<property name="user.name" value="anon"/>
<property name="stdout.encoding" value="UTF-8"/>
<property name="path.separator" value=":"/>
<property name="os.version" value="6.7.2-gentoo-r1"/>
<property name="java.runtime.name" value="OpenJDK Runtime Environment"/>
<property name="file.encoding" value="UTF-8"/>
<property name="java.vm.name" value="OpenJDK 64-Bit Server VM"/>
<property name="java.vendor.version" value="Temurin-21.0.3+9"/>
<property name="localRepository" value="/home/anon/.m2/repository"/>
<property name="java.vendor.url.bug" value="https://github.com/adoptium/adoptium-support/issues"/>
<property name="java.io.tmpdir" value="/tmp"/>
<property name="java.version" value="21.0.3"/>
<property name="user.dir" value="/home/anon/Swap/school/patterns/jumpin"/>
<property name="os.arch" value="amd64"/>
<property name="java.vm.specification.name" value="Java Virtual Machine Specification"/>
<property name="native.encoding" value="UTF-8"/>
<property name="java.library.path" value="/usr/java/packages/lib:/usr/lib64:/lib64:/lib:/usr/lib"/>
<property name="java.vm.info" value="mixed mode, sharing"/>
<property name="stderr.encoding" value="UTF-8"/>
<property name="java.vendor" value="Eclipse Adoptium"/>
<property name="java.vm.version" value="21.0.3+9-LTS"/>
<property name="sun.io.unicode.encoding" value="UnicodeLittle"/>
<property name="java.class.version" value="65.0"/>
</properties>
<testcase name="mustSellSimple" classname="MarketTests" time="0.004"/>
<testcase name="newSellers" classname="MarketTests" time="0.0"/>
<testcase name="invalidSellerSelected" classname="MarketTests" time="0.0"/>
<testcase name="invalidSeller" classname="MarketTests" time="0.0"/>
<testcase name="testTest" classname="MarketTests" time="0.001"/>
<testcase name="newMarget" classname="MarketTests" time="0.001"/>
<testcase name="newBasicBuy" classname="MarketTests" time="0.001"/>
<testcase name="SellerFactoryMethod" classname="MarketTests" time="0.0"/>
<testcase name="mustNotSellGreedy" classname="MarketTests" time="0.002"/>
<testcase name="mustNotSellCompromizing" classname="MarketTests" time="0.0"/>
</testsuite>

58
Java/jumpin/txt.txt Normal file

@ -0,0 +1,58 @@
>TTD
### nagybani piac program: ###
>kontainer osztály (eladó lista)
>alma & körte árulás
>mást is lehessen árulni
-eladók:
>más árak
>alma & körte
>alku
>miből hány kiló
>mennyiért
-vásárlás(mi, mennyi, mennyiért) -> visszatérési ár: kereskedő válasza
if mennyi == r -> siker
>más alku stratégiák
>előző verziók megjegyzésbe
### Minták kidolgozásra ###
>stratégia
>prototype
>szabad
Stratégia:
>a stratégia viselkedés mint adat
>OOP-ben mint osztály
>alakalmazásával elkerülthető az alfaj robbanás
>segithet elkerültni mocskos if-else blockokat
>használata triviális, az új osztáj hierarchia szerepe néhány metódus
implementágása
>intuitív, álltalában akkor nem kerül alkalmazásra a viselkedés
complexitás mögött megbújik
>további előnye, hogy a viselkedés módosíthatóvá tehető a példány élet
ideje alatt
{
kacsák
van egy a beugróban
self.(menü példa)
}
Prototype:
>(túl egyszerű)
>ha egy példány létrehozás kölcséges akkor lehet,
hogy a clónozása olcsóbb
>álltalában egy cloneable interface-el és egy clone() metódussal
implementálják
>új példányokat létezőkből hozunk létre
>létező példányok le "cache"-elése lehetséges
Factory:
>polimorfikus alosztály generálás központja
>elhárít töbször ismételt if-else logikát
>a factory felhasználója decoupling-re kerül az alosztályoktól
>paraméterezéssel történi a megfelelő alosztály kiválasztása
>lehet metódus alalapon implementálva ahol a class *Factory egy metódusa
adja vissza a megfelelő osztályt (ez lehet statukus /* vagy szabad*/)
>segít a "ne használjuk new kulcsszó" tanács alkalmazását
>lehet több párhuzamos class hierarchiát egy abstract Factory osztályal
egy interface-re hozni { chicago/(new york) pizza gyáral}