-
Notifications
You must be signed in to change notification settings - Fork 25
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
1c96108
commit 3727000
Showing
24 changed files
with
316 additions
and
177 deletions.
There are no files selected for viewing
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
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
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
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
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
75 changes: 75 additions & 0 deletions
75
libCompiler/src/test/java/com/duy/pascal/java/JavaCollectionsTest.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,75 @@ | ||
package com.duy.pascal.java;/* | ||
* Copyright (c) 2017 Tran Le Duy | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
|
||
import com.duy.pascal.interpreter.BaseTestCase; | ||
|
||
import java.io.File; | ||
|
||
/** | ||
* Created by Duy on 17-Jun-17. | ||
*/ | ||
|
||
public class JavaCollectionsTest extends BaseTestCase { | ||
@Override | ||
public String getDirTest() { | ||
return "test_libraries" + File.separator + "javacollections"; | ||
} | ||
|
||
|
||
public void testArrayList() { | ||
run("ArrayList.pas"); | ||
} | ||
|
||
public void testHashMap() { | ||
run("HashMap.pas"); | ||
} | ||
|
||
public void testHashSet() { | ||
run("HashSet.pas"); | ||
|
||
} | ||
|
||
public void testLinkedHashMap() { | ||
run("LinkedHashMap.pas"); | ||
|
||
} | ||
|
||
public void testLinkedHashSet() { | ||
run("LinkedHashSet.pas"); | ||
|
||
} | ||
|
||
public void testLinkedList() { | ||
run("LinkedList.pas"); | ||
|
||
} | ||
|
||
public void testStack() { | ||
run("Stack.pas"); | ||
|
||
} | ||
|
||
public void testTreeSet() { | ||
run("TreeSet.pas"); | ||
|
||
} | ||
|
||
public void testVector() { | ||
run("Vector.pas"); | ||
|
||
} | ||
} |
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,5 @@ | ||
Initial size of list : 0 | ||
Size of list after additions : 7 | ||
Contents of list : [C, A2, A, E, B, D, F] | ||
Size of list after deletions : 6 | ||
Contents of list : [C, A2, A, E, B, D] |
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,27 @@ | ||
uses JavaCollections; | ||
|
||
var | ||
list : JArrayList; | ||
begin | ||
writeln('Initial size of list : ' + list.size()); | ||
|
||
// add elements to the array list | ||
list.add('C'); | ||
list.add('A'); | ||
list.add('E'); | ||
list.add('B'); | ||
list.add('D'); | ||
list.add('F'); | ||
list.add(1, 'A2'); | ||
writeln('Size of list after additions : ' + list.size()); | ||
|
||
// display the array list | ||
writeln('Contents of list : ' + list); | ||
|
||
// Remove elements from the array list | ||
list.remove('F'); | ||
list.remove(2); | ||
writeln('Size of list after deletions : ' + list.size()); | ||
writeln('Contents of list : ' + list); | ||
end. | ||
{https://www.tutorialspoint.com/java/java_arraylist_class.htm} |
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,40 @@ | ||
{https://www.tutorialspoint.com/java/java_hashmap_class.htm} | ||
uses JavaCollections; | ||
|
||
var | ||
// Create a hash map | ||
map : JHashMap; | ||
entries : JSet; | ||
i : JIterator; | ||
entry : JEntry; | ||
balance : Double; | ||
begin | ||
// Put elements to the map | ||
map.put('Zara', (3434.34)); | ||
map.put('Mahnaz', (123.22)); | ||
map.put('Ayan', (1378.00)); | ||
map.put('Daisy', (99.22)); | ||
map.put('Qadir', (-19.08)); | ||
|
||
// Get a set of the entries | ||
entries := map.entrySet(); | ||
|
||
// Get an iterator | ||
i := entries.iterator(); | ||
writeln(i); | ||
|
||
// Display elements | ||
while(i.hasNext()) do | ||
begin | ||
cast(entry, i.next()); | ||
write(entry.getKey() + ' : '); | ||
writeln(entry.getValue()); | ||
end; | ||
|
||
// Deposit 1000 into Zara's account | ||
writeln(map.get('Zara')); | ||
|
||
cast(balance, map.get('Zara')); | ||
map.put('Zara', (balance + 1000)); | ||
writeln('Zara''s new balance : ' + map.get('Zara')); | ||
end. |
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 @@ | ||
[A, B, C, D, E, F] |
2 changes: 2 additions & 0 deletions
2
...ascal/test_libraries/javautil/hashset.pas → ...est_libraries/javacollections/HashSet.pas
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 |
---|---|---|
@@ -1,3 +1,5 @@ | ||
uses JavaCollections; | ||
|
||
var | ||
// create a hash set | ||
hs : JHashSet; | ||
|
Oops, something went wrong.