Question
Please make the comment code in java thanks! private TransactionSeq s; Account a1 = new Account(A); Account a2 = new Account(B); Account a3 = new
Please make the comment code in java thanks!
private TransactionSeq s; Account a1 = new Account("A"); Account a2 = new Account("B"); Account a3 = new Account("C"); Transaction t1 = new Transaction(a1, a2, new Money(1)); Transaction t2 = new Transaction(a1, a2, new Money(2)); Transaction t3 = new Transaction(a1, a2, new Money(3)); Transaction t4 = new Transaction(a1, a2, new Money(4)); Transaction t5 = new Transaction(a1, a2, new Money(5)); Transaction t[] = { null, t1, t2, t3, t4, t5 }; // String resultString = result.toString();
// Using the above array // convert a Transaction result to a String: // e.g.: null, t1, t2 etc. // if the expression causes an error, the result is the name of the exception // If the transaction is not in the array, the result will be t? // ("t" followed by question mark) String tx(Supplier
protected void assertException(Class extends Throwable> c, Runnable r) { try { r.run(); assertFalse("Exception should have been thrown",true); } catch (RuntimeException ex) { assertTrue("should throw exception of " + c + ", not of " + ex.getClass(), c.isInstance(ex)); } } // This test tests many things. // We recommend that you run the UnlockTests to unlock all its tests at once. public void test() { assertEquals(Ti(887770454),s.size()); // In the following, if a Transaction index is called for ("tx"), answer: // null if the result will be null // t1 if the result will be the Transaction t1 // t2 if the result will be the Transaction t2 // etc. // t? if it's some other transaction // If the code will crash with an exception, give the name of that exception. assertEquals(Ts(633649182),tx(() -> s.getCurrent())); s.addBefore(t1); assertEquals(Ts(1660127832),tx(() -> s.getCurrent())); s.addAfter(null); assertEquals(Ts(210441353),tx(() -> s.getCurrent())); s.addBefore(t3); assertEquals("t3",tx(() -> s.getCurrent())); s.advance(); assertEquals(Ts(925451150),tx(() -> s.getCurrent())); s.advance(); assertEquals(Ts(731166162),tx(() -> s.getCurrent())); s.addBefore(new Transaction(a1,a2,new Money(2))); // looks like t2, but not assertEquals(Ts(944599671),tx(() -> s.getCurrent())); s.advance(); assertEquals(Ts(365773574),tx(() -> s.getCurrent())); testcont(s); testremove(s); } // Continuation of test: private void testcont(TransactionSeq s) { s.start(); s.advance(); s.advance(); assertNull(s.getCurrent()); // At this point s is [t1,t3,*null,t?] with * marking current TransactionSeq s2 = new TransactionSeq(); assertEquals(true,s2.atEnd()); // In the following, if a Transaction index is called for ("tx"), answer: // null if the result will be null // t1 if the result will be the Transaction t1 // t2 if the result will be the Transaction t2 // etc. // t? if it's some other transaction // If the code will crash with an exception, give the name of that exception. s2.addBefore(t4); assertEquals(false,s2.atEnd()); s2.addAfter(t5); assertEquals("t5",tx(() -> s2.getCurrent())); s.addAll(s2); assertEquals(Ti(566769707),s.size()); // What does addAll() say about what is current afterwards? assertEquals(Ts(971614681),tx(()->s.getCurrent())); assertEquals(Ts(424383275),tx(() -> s2.getCurrent())); s.advance(); assertEquals(Ts(1530122758),tx(()->s.getCurrent())); s.advance(); assertEquals(Ts(338431101),tx(()->s.getCurrent())); } // continuation of test private void testremove(TransactionSeq s) { // s is [t1, t3, null, t?, *t4, t5] where * marks current element // In the following, if a Transaction index is called for ("tx"), answer: // null if the result will be null // t1 if the result will be the Transaction t1 // t2 if the result will be the Transaction t2 // etc. // t? if it's some other transaction // If the code will crash with an exception, give the name of that exception. s.removeCurrent(); assertEquals(Ts(2071918479),tx(() -> s.getCurrent())); s.advance(); assertEquals(Ts(988172611),tx(() -> s.getCurrent())); assertEquals(Tb(1809270213),s.atEnd()); s.removeCurrent(); assertEquals(Tb(1429063010),s.atEnd()); assertEquals("IllegalStateException",tx(() -> s.getCurrent())); s.start(); s.removeCurrent(); assertFalse(s.isCurrent()); s.advance(); assertEquals(Ts(1562168809),tx(() -> s.getCurrent())); }
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started