程序代写 package comp1110.exam;

package comp1110.exam;

import org.junit.FixMethodOrder;
import org.junit.Rule;

Copyright By PowCoder代写 加微信 powcoder

import org.junit.Test;
import org.junit.rules.Timeout;
import org.junit.runners.MethodSorters;

import static org.junit.Assert.assertTrue;

@FixMethodOrder(MethodSorters.NAME_ASCENDING)
public class Q2SimpleStockManagerTest {
public Timeout globalTimeout = Timeout.millis(4000);

public void testAddGetOne() {
Q2SimpleStockManager sm = new Q2SimpleStockManager();
sm.newItem(“1234”, “Jam”, 3.25);
String name = sm.getItemName(“1234”);
assertTrue(“Expected ‘Jam’, but got ‘”+name, name.equals(“Jam”));
double price = sm.getItemPrice(“1234”);
assertTrue(“Expected 3.25, but got ‘”+price, price==3.25);

public void testAddGetTwo() {
Q2SimpleStockManager sm = new Q2SimpleStockManager();
sm.newItem(“1234”, “Jam”, 3.25);
sm.newItem(“5678”, “Coffee”, 4.37);

String name = sm.getItemName(“5678”);
assertTrue(“Expected ‘Coffee’, but got ‘”+name, name.equals(“Coffee”));
double price = sm.getItemPrice(“5678”);
assertTrue(“Expected 4.37, but got “+price, price==4.37);

public void testAddGetThree() {
Q2SimpleStockManager sm = new Q2SimpleStockManager();
sm.newItem(“1234”, “Jam”, 3.25);
sm.newItem(“5678”, “Coffee”, 4.37);
sm.newItem(“ABCD”, “Eggs”, 3.98);

String name = sm.getItemName(“5678”);
assertTrue(“Expected ‘Coffee’, but got ‘”+name, name.equals(“Coffee”));
double price = sm.getItemPrice(“5678”);
assertTrue(“Expected 4.37, but got “+price, price==4.37);
price = sm.getItemPrice(“ABCD”);
assertTrue(“Expected 3.98, but got “+price, price==3.98);

public void testSaleGetStock() {
Q2SimpleStockManager sm = new Q2SimpleStockManager();
sm.newItem(“1234”, “Jam”, 3.25);
sm.addStock(“1234”, 100);

sm.sale(“1234”,4);
sm.sale(“1234”,2);
int stock = sm.getStock(“1234”);
assertTrue(“Expected 94, but got “+stock, stock == 94);

public void testSaleGetStockTwo() {
Q2SimpleStockManager sm = new Q2SimpleStockManager();
sm.newItem(“1234”, “Jam”, 3.25);
sm.addStock(“1234”, 100);
sm.newItem(“5678”, “Coffee”, 4.37);
sm.addStock(“5678”, 37);

sm.sale(“1234”,4);
sm.sale(“1234”,2);
sm.sale(“5678”,20);
int stock = sm.getStock(“1234”);
assertTrue(“Expected 94, but got “+stock, stock == 94);
stock = sm.getStock(“5678”);
assertTrue(“Expected 17, but got “+stock, stock == 17);
public void testSaleGetStockThree() {
Q2SimpleStockManager sm = new Q2SimpleStockManager();
sm.newItem(“1234”, “Jam”, 3.25);
sm.addStock(“1234”, 100);
sm.newItem(“5678”, “Coffee”, 4.37);
sm.addStock(“5678”, 37);

sm.sale(“1234”,4);
sm.addStock(“1234”, 7);
sm.sale(“1234”,2);
sm.sale(“5678”,20);
sm.addStock(“5678”, 10);
int stock = sm.getStock(“1234”);
assertTrue(“Expected 101, but got “+stock, stock == 101);
stock = sm.getStock(“5678”);
assertTrue(“Expected 27, but got “+stock, stock == 27);

public void testTargetStock() {
Q2SimpleStockManager sm = new Q2SimpleStockManager();
sm.newItem(“1234”, “Jam”, 3.25);
sm.addStock(“1234”, 100);
sm.setTargetStock(“1234”, 90);
sm.sale(“1234”,14);
int required = sm.getStockRequired(“1234”);
assertTrue(“Expected 4, but got “+required, required == 4);

public void testTargetStockTwo() {
Q2SimpleStockManager sm = new Q2SimpleStockManager();
sm.newItem(“1234”, “Jam”, 3.25);
sm.newItem(“5678”, “Coffee”, 4.37);
sm.addStock(“5678”, 37);
sm.addStock(“1234”, 100);
sm.setTargetStock(“1234”, 90);
sm.setTargetStock(“5678”, 40);
sm.sale(“1234”,14);
int required = sm.getStockRequired(“1234”);
assertTrue(“Expected 4, but got “+required, required == 4);
required = sm.getStockRequired(“5678”);
assertTrue(“Expected 3, but got “+required, required == 3);

public void testActualStock() {
Q2SimpleStockManager sm = new Q2SimpleStockManager();
sm.newItem(“1234”, “Jam”, 3.25);
sm.addStock(“1234”, 100);
sm.setTargetStock(“1234”, 90);
sm.sale(“1234”,14);
int loss = sm.setActualStock(“1234”, 50);
assertTrue(“Expected difference of -36, but got “+loss, loss == -36);

public void testActualStockTwo() {
Q2SimpleStockManager sm = new Q2SimpleStockManager();
sm.newItem(“1234”, “Jam”, 3.25);
sm.addStock(“1234”, 100);
sm.setTargetStock(“1234”, 90);
sm.sale(“1234”,14);
sm.setActualStock(“1234”, 50);
sm.setTargetStock(“1234”, 40);
sm.sale(“1234”,14);
int required = sm.getStockRequired(“1234”);
assertTrue(“Expected 4, but got “+required, required == 4);

程序代写 CS代考 加微信: powcoder QQ: 1823890830 Email: powcoder@163.com