-
Notifications
You must be signed in to change notification settings - Fork 641
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #27 from Memory-Cunese/master
Memory-Cunese 1778842360 第三次作业提交
- Loading branch information
Showing
9 changed files
with
1,159 additions
and
0 deletions.
There are no files selected for viewing
518 changes: 518 additions & 0 deletions
518
group26/1778842360/third homework/LinkedList/LinkedList.java
Large diffs are not rendered by default.
Oops, something went wrong.
192 changes: 192 additions & 0 deletions
192
group26/1778842360/third homework/LinkedList/LinkedListTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,192 @@ | ||
package first; | ||
|
||
import org.junit.After; | ||
import org.junit.Assert; | ||
import org.junit.Before; | ||
import org.junit.Test; | ||
|
||
|
||
public class LinkedListTest { | ||
|
||
@Before | ||
public void setUp() throws Exception { | ||
} | ||
|
||
@After | ||
public void tearDown() throws Exception { | ||
} | ||
@Test | ||
public void testReverse() { | ||
LinkedList l=new LinkedList(); | ||
Assert.assertEquals("[]", l.toString()); | ||
|
||
l.add(1); | ||
l.reverse(); | ||
Assert.assertEquals("[1]", l.toString()); | ||
|
||
l.add(2); | ||
l.add(3); | ||
l.add(4); | ||
l.reverse(); | ||
Assert.assertEquals("[4,3,2,1]", l.toString()); | ||
} | ||
@Test | ||
public void testRemoveFirstHalf() | ||
{ | ||
LinkedList l1=new LinkedList(); | ||
l1.add(3); | ||
l1.add(4); | ||
l1.add(5); | ||
l1.add(6); | ||
l1.add(7); | ||
l1.removeFirstHalf(); | ||
Assert.assertEquals("[5,6,7]", l1.toString()); | ||
} | ||
@Test | ||
public void testRemoveIntInt() | ||
{ | ||
{ | ||
LinkedList l1=new LinkedList(); | ||
l1.add(3); | ||
l1.add(4); | ||
l1.add(5); | ||
l1.add(6); | ||
l1.add(7); | ||
l1.remove(0,3); | ||
Assert.assertEquals("[6,7]", l1.toString()); | ||
} | ||
{ | ||
LinkedList l1=new LinkedList(); | ||
l1.add(3); | ||
l1.add(4); | ||
l1.add(5); | ||
l1.add(6); | ||
l1.add(7); | ||
l1.remove(1,3); | ||
Assert.assertEquals("[3,7]", l1.toString()); | ||
} | ||
} | ||
@Test | ||
public void testGetElement() | ||
{ | ||
LinkedList linkedList=new LinkedList(); | ||
linkedList.add(11); | ||
linkedList.add(101); | ||
linkedList.add(201); | ||
linkedList.add(301); | ||
linkedList.add(401); | ||
linkedList.add(501); | ||
linkedList.add(601); | ||
linkedList.add(701); | ||
LinkedList list=new LinkedList(); | ||
list.add(1); | ||
list.add(3); | ||
list.add(4); | ||
list.add(6); | ||
Assert.assertEquals("[101,301,401,601]", linkedList.getElements(list)); | ||
} | ||
@Test | ||
public void testSubstract() | ||
{ | ||
LinkedList list1 = new LinkedList(); | ||
list1.add(101); | ||
list1.add(201); | ||
list1.add(301); | ||
list1.add(401); | ||
list1.add(501); | ||
list1.add(601); | ||
list1.add(701); | ||
|
||
LinkedList list2 = new LinkedList(); | ||
|
||
list2.add(101); | ||
list2.add(201); | ||
list2.add(301); | ||
list2.add(401); | ||
list2.add(501); | ||
|
||
list1.subtract(list2); | ||
Assert.assertEquals("[601,701]", list1.toString()); | ||
} | ||
@Test | ||
public void testRemoveDuplicateValues(){ | ||
LinkedList list1 = new LinkedList(); | ||
list1.add(101); | ||
list1.add(101); | ||
list1.add(301); | ||
list1.add(301); | ||
list1.add(501); | ||
list1.add(701); | ||
list1.add(701); | ||
list1.removeDuplicateValues(); | ||
Assert.assertEquals("[101,301,501,701]", list1.toString()); | ||
} | ||
@Test | ||
public void testRemoveRange() | ||
{ | ||
{ | ||
LinkedList linkedList = new LinkedList(); | ||
|
||
linkedList.add(11); | ||
linkedList.add(12); | ||
linkedList.add(13); | ||
linkedList.add(14); | ||
linkedList.add(16); | ||
linkedList.add(16); | ||
linkedList.add(19); | ||
|
||
linkedList.removeRange(10, 19); | ||
Assert.assertEquals("[19]", linkedList.toString()); | ||
} | ||
{ | ||
LinkedList linkedList = new LinkedList(); | ||
|
||
linkedList.add(11); | ||
linkedList.add(12); | ||
linkedList.add(13); | ||
linkedList.add(14); | ||
linkedList.add(16); | ||
linkedList.add(16); | ||
linkedList.add(19); | ||
|
||
linkedList.removeRange(13, 19); | ||
Assert.assertEquals("[11,12,19]", linkedList.toString()); | ||
} | ||
} | ||
@Test | ||
public void testInterSection() | ||
{ | ||
{ | ||
LinkedList list1 = new LinkedList(); | ||
list1.add(1); | ||
list1.add(6); | ||
list1.add(7); | ||
|
||
LinkedList list2 = new LinkedList(); | ||
list2.add(2); | ||
list2.add(5); | ||
list2.add(6); | ||
|
||
LinkedList newList = list1.intersection(list2); | ||
Assert.assertEquals("[6]", newList.toString()); | ||
} | ||
{ | ||
LinkedList list1 = new LinkedList(); | ||
list1.add(1); | ||
list1.add(6); | ||
list1.add(7); | ||
list1.add(9); | ||
|
||
LinkedList list2 = new LinkedList(); | ||
list2.add(1); | ||
list2.add(2); | ||
list2.add(5); | ||
list2.add(6); | ||
list2.add(9); | ||
|
||
LinkedList newList = list1.intersection(list2); | ||
Assert.assertEquals("[1,6,9]", newList.toString()); | ||
} | ||
} | ||
|
||
} |
41 changes: 41 additions & 0 deletions
41
group26/1778842360/third homework/TTD/ConfigurationTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
package com.coderising.litestruts; | ||
|
||
import org.junit.After; | ||
import org.junit.Assert; | ||
import org.junit.Before; | ||
import org.junit.Test; | ||
|
||
public class ConfigurationTest { | ||
Configureation cfg=new Configureation("struts.xml"); | ||
@Before | ||
public void setUp() throws Exception{ | ||
|
||
} | ||
@After | ||
public void TearDown() throws Exception{ | ||
|
||
} | ||
@Test | ||
public void testGetClassName() { | ||
String clzName=cfg.getClassName("login"); | ||
Assert.assertEquals("com.coderising.litestruts.LoginAction", clzName); | ||
clzName=cfg.getClassName("loginout"); | ||
Assert.assertEquals("com.coderising.litestruts.LoginAction", clzName); | ||
} | ||
@Test | ||
public void tsetGetResult() | ||
{ | ||
String jsp=cfg.getResultView("login", "success"); | ||
Assert.assertEquals("/jsp/homepage.jsp",jsp); | ||
jsp=cfg.getResultView("login", "fail"); | ||
Assert.assertEquals("/jsp/showLogin.jsp",jsp); | ||
jsp=cfg.getResultView("logout", "success"); | ||
Assert.assertEquals("/jsp/welcome.jsp",jsp); | ||
jsp=cfg.getResultView("logout", "error"); | ||
Assert.assertEquals("/jsp/error.jsp",jsp); | ||
} | ||
|
||
|
||
|
||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,99 @@ | ||
package com.coderising.litestruts; | ||
|
||
import java.io.IOException; | ||
import java.io.InputStream; | ||
import java.util.HashMap; | ||
import java.util.Map; | ||
|
||
import org.jdom2.Document; | ||
import org.jdom2.Element; | ||
import org.jdom2.JDOMException; | ||
import org.jdom2.input.SAXBuilder; | ||
|
||
public class Configureation { | ||
Map<String,ActionConfig> actions=new HashMap<>(); | ||
|
||
public Configureation(String fileName) | ||
{ | ||
String packageName=this.getClass().getPackage().getName(); | ||
packageName=packageName.replace('.', '/'); | ||
InputStream is=this.getClass().getResourceAsStream("/"+packageName+"/"+fileName); | ||
parseXML(is); | ||
|
||
try{ | ||
is.close(); | ||
} | ||
catch(IOException e){ | ||
e.printStackTrace(); | ||
} | ||
} | ||
|
||
private void parseXML(InputStream is) { | ||
|
||
SAXBuilder builder=new SAXBuilder(); | ||
|
||
try{ | ||
Document doc=builder.build(is); | ||
Element root =doc.getRootElement(); | ||
for(Element actionElement :root.getChildren("action")) | ||
{ | ||
String actionName=actionElement.getAttributeValue("name"); | ||
String clzName=actionElement.getAttributeValue("class"); | ||
ActionConfig ac=new ActionConfig(actionName,clzName); | ||
for(Element resultElement:actionElement.getChildren()) | ||
{ | ||
String resultName=resultElement.getAttributeValue("name"); | ||
String viewName=resultElement.getText().trim(); | ||
|
||
ac.addViewResult(resultName, viewName); | ||
|
||
} | ||
this.actions.put(actionName, ac);//把actionName以及其下面的resultName和viewName构成一个键值对 | ||
} | ||
} | ||
catch(JDOMException e){ | ||
e.printStackTrace(); | ||
} catch(IOException e) | ||
{ | ||
e.printStackTrace(); | ||
} | ||
} | ||
|
||
public String getClassName(String action) { | ||
ActionConfig ac=this.actions.get(action); | ||
if(ac==null) | ||
{ | ||
return null; | ||
} | ||
return ac.getClassName(); | ||
} | ||
|
||
public String getResultView(String action,String resultName) | ||
{ | ||
ActionConfig ac=this.actions.get(action); | ||
if(ac==null){ | ||
return null; | ||
} | ||
return ac.getViewName(resultName); | ||
} | ||
private static class ActionConfig{ | ||
String name; | ||
String clzName; | ||
Map<String,String> viewResult=new HashMap<>(); | ||
|
||
public ActionConfig(String actionName,String clzName){ | ||
this.name=actionName; | ||
this.clzName=clzName; | ||
} | ||
public String getClassName(){ | ||
return clzName; | ||
} | ||
public void addViewResult(String name,String viewName){ | ||
viewResult.put(name, viewName); | ||
} | ||
public String getViewName(String resultName) | ||
{ | ||
return viewResult.get(resultName); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
package com.coderising.litestruts; | ||
|
||
public class LoginAction { | ||
|
||
private String name; | ||
private String password; | ||
private String message; | ||
|
||
public String getName() | ||
{ | ||
return name; | ||
} | ||
|
||
public String getPassword() | ||
{ | ||
return password; | ||
} | ||
|
||
public String execute(){ | ||
if("test".equals(name) && "1234".equals(password)) | ||
{ | ||
this.message="login successful"; | ||
return "success"; | ||
} | ||
this.message="login failed,please check you user/pwd"; | ||
return "fail"; | ||
} | ||
public void setName(String name) { | ||
|
||
this.name=name; | ||
} | ||
|
||
public void setPassword(String password) { | ||
|
||
this.password=password; | ||
} | ||
public String getMessage() | ||
{ | ||
return message; | ||
} | ||
|
||
} |
Oops, something went wrong.