Mercurial > hg > RemoteEditor > REPSessionManager
comparison test/RepCommandOptimizeTest.java @ 331:f9fa876d3539
Optimizer test
author | kono |
---|---|
date | Sun, 12 Oct 2008 09:43:17 +0900 |
parents | 5b7abc22e61a |
children | 6f356d160e58 |
comparison
equal
deleted
inserted
replaced
330:ddfc786811b9 | 331:f9fa876d3539 |
---|---|
21 Integer.toString(REP.REPCMD_DELETE.id),"d","13","5", | 21 Integer.toString(REP.REPCMD_DELETE.id),"d","13","5", |
22 Integer.toString(REP.REPCMD_DELETE.id),"d","3","6", | 22 Integer.toString(REP.REPCMD_DELETE.id),"d","3","6", |
23 Integer.toString(REP.REPCMD_DELETE.id),"d","1","7", | 23 Integer.toString(REP.REPCMD_DELETE.id),"d","1","7", |
24 Integer.toString(REP.REPCMD_INSERT.id),"A","5","8", | 24 Integer.toString(REP.REPCMD_INSERT.id),"A","5","8", |
25 Integer.toString(REP.REPCMD_DELETE.id),"d","1","9", | 25 Integer.toString(REP.REPCMD_DELETE.id),"d","1","9", |
26 Integer.toString(REP.REPCMD_DELETE.id),"d","1","10", | 26 Integer.toString(REP.REPCMD_DELETE.id),"d","0","10", |
27 Integer.toString(REP.REPCMD_INSERT.id),"B","10","11", | 27 Integer.toString(REP.REPCMD_INSERT.id),"B","10","11", |
28 Integer.toString(REP.REPCMD_INSERT.id),"B","1","12", | |
29 Integer.toString(REP.REPCMD_INSERT.id),"C","3","13", | 28 Integer.toString(REP.REPCMD_INSERT.id),"C","3","13", |
30 Integer.toString(REP.REPCMD_DELETE.id),"d","2","14", | 29 Integer.toString(REP.REPCMD_DELETE.id),"d","2","14", |
30 Integer.toString(REP.REPCMD_DELETE.id),"d","0","14", | |
31 Integer.toString(REP.REPCMD_DELETE.id),"d","3","15", | 31 Integer.toString(REP.REPCMD_DELETE.id),"d","3","15", |
32 Integer.toString(REP.REPCMD_DELETE.id),"d","1","16", | 32 Integer.toString(REP.REPCMD_DELETE.id),"d","1","16", |
33 Integer.toString(REP.REPCMD_INSERT.id),"A","3","17", | 33 Integer.toString(REP.REPCMD_INSERT.id),"A","0","17", |
34 Integer.toString(REP.REPCMD_DELETE.id),"d","1","18" | 34 Integer.toString(REP.REPCMD_INSERT.id),"K","0","17", |
35 Integer.toString(REP.REPCMD_DELETE.id),"d","1","18", | |
36 Integer.toString(REP.REPCMD_NOP.id),"","0","19", | |
37 Integer.toString(REP.REPCMD_NOP.id),"","0","20", | |
35 }; | 38 }; |
36 | 39 |
37 static private String[] text1d = { | 40 static private String[] text1d = { |
38 "aaa", "bbb", "ccc", "ddd", "eee", | 41 "aaa", "bbb", "ccc", "ddd", "eee", |
39 "fff", "ggg", "hhh", "iii", "jjj", | 42 "fff", "ggg", "hhh", "iii", "jjj", |
46 "aaa", "bbb", "ccc", "ddd", "eee", | 49 "aaa", "bbb", "ccc", "ddd", "eee", |
47 "fff", "ggg", "hhh", "iii", "jjj", | 50 "fff", "ggg", "hhh", "iii", "jjj", |
48 "kkk", "lll", "mmm", "nnn", "ooo", | 51 "kkk", "lll", "mmm", "nnn", "ooo", |
49 "ppp", "qqq", "rrr", "sss", "ttt", | 52 "ppp", "qqq", "rrr", "sss", "ttt", |
50 "uuu", "vvv", "www", "xxx", "yyy", "zzz" | 53 "uuu", "vvv", "www", "xxx", "yyy", "zzz" |
51 }; | 54 }; |
55 | |
56 private static int err=0; | |
52 | 57 |
53 public static List<REPCommand> makeCommandList(String[] str){ | 58 public static List<REPCommand> makeCommandList(String[] str){ |
54 int seq = 0; | 59 int seq = 0; |
55 LinkedList<REPCommand> cmdlist = new LinkedList<REPCommand>(); | 60 LinkedList<REPCommand> cmdlist = new LinkedList<REPCommand>(); |
56 try{ | 61 try{ |
84 REPCommandOptimizer rco; | 89 REPCommandOptimizer rco; |
85 | 90 |
86 if (true) rco = new DeleteInsertOptimizer(); // | 91 if (true) rco = new DeleteInsertOptimizer(); // |
87 else rco = new NullOptimizer(); // なにも最適化しない | 92 else rco = new NullOptimizer(); // なにも最適化しない |
88 | 93 |
89 List<REPCommand> result = new LinkedList<REPCommand>(); | |
90 List<REPCommand> cmdlist; | 94 List<REPCommand> cmdlist; |
91 Text text1 = new Text(text1d); | |
92 Text text2 = new Text(text2d); | |
93 | 95 |
94 cmdlist = makeCommandList(test1); | 96 cmdlist = makeCommandList(test1); |
95 java.util.Collections.shuffle(cmdlist); | 97 int total = 0; |
96 | 98 while(cmdlist.size()>0) { |
99 Text text1 = new Text(text1d); | |
100 Text text2 = new Text(text2d); | |
101 java.util.Collections.shuffle(cmdlist); | |
102 test(rco, cmdlist, text1, text2); | |
103 total++; | |
104 cmdlist.remove(0); | |
105 } | |
106 System.out.println("Errors "+err+"/"+total+"."); | |
107 | |
108 } | |
109 | |
110 | |
111 private static void test(REPCommandOptimizer rco, List<REPCommand> cmdlist, | |
112 Text text1, Text text2) { | |
113 List<REPCommand> result; // optimize | |
114 // this command list is applied to a text. and print the text. | |
115 text1.edit(cmdlist); | |
116 result = rco.optimize(cmdlist); | |
117 // this command list applied to other text, and print it. | |
118 text2.edit(result); | |
119 // check two texts. | |
120 if(!text1.equals(text2)){ | |
121 System.out.println("two texts not match"); | |
122 print(cmdlist, result, text1, text2); | |
123 err++; | |
124 } | |
125 } | |
126 | |
127 private static void print(List<REPCommand> cmdlist, | |
128 List<REPCommand> result, | |
129 Text text1, Text text2) { | |
130 | |
97 // print non optimized command list | 131 // print non optimized command list |
98 System.out.println("---------- CmdList before optimized ----------"); | 132 System.out.println("---------- CmdList before optimized ----------"); |
99 printCmdList(cmdlist); | 133 printCmdList(cmdlist); |
100 | 134 |
101 // this command list is applied to a text. and print the text. | |
102 text1.edit(cmdlist); | |
103 System.out.println("---text which applied above commands---"); | |
104 printText(text1); | |
105 | |
106 // optimize | |
107 result = rco.optimize(cmdlist); | |
108 | |
109 // print optimized command list. | 135 // print optimized command list. |
110 System.out.println("---------- CmdList after optimized ----------"); | 136 System.out.println("---------- CmdList after optimized ----------"); |
111 printCmdList(result); | 137 printCmdList(result); |
112 | 138 |
113 // this command list applied to other text, and print it. | 139 System.out.println("---------- Text difference ------------------"); |
114 text2.edit(result); | 140 int max = max(text1.size(),text2.size()); |
115 System.out.println("---text which applied above commands---"); | 141 for(int i=0;i<max;i++) { |
116 printText(text1); | 142 System.out.println(i+":\t"+text1.get(i)+"\t"+text2.get(i)); |
143 } | |
144 } | |
117 | 145 |
118 // check two texts. | 146 |
119 if(text1.equals(text2)){ | 147 |
120 System.out.println("two texts match."); | 148 private static int max(int size, int size2) { |
121 }else{ | 149 return size>size2?size:size2; |
122 System.out.println("two texts not match"); | 150 } |
123 } | |
124 | 151 |
125 } | 152 } |
126 } | 153 |