My mobile apps: (Beginner Level)
https://play.google.com/store/search?q=Codejer
My mobile apps:(Intermediate Level)
https://play.google.com/store/apps/details?id=sota.travel.virtualtravelfair
Thursday, 21 November 2013
My first article on mobile apps
Reviewing and comparing maps application on most popular smart phone operating system.
http://www.virtualmalaysia.com/head-to-head-how-ios-maps-stack-up-against-google-maps/
http://www.virtualmalaysia.com/head-to-head-how-ios-maps-stack-up-against-google-maps/
Startup Lesson
Great tips for startup.
http://wefurniture.wordpress.com/2013/11/14/7-lessons-every-startup-should-know-mashable/
http://wefurniture.wordpress.com/2013/11/14/7-lessons-every-startup-should-know-mashable/
Wednesday, 10 October 2012
PhoneGap Pinch Zoom
These code will allow pinch zoom in PhoneGap application.
1. index.html.
<meta name="viewport" content="width=device-width, height=device-height, initial-scale=0.8, user-scalable=1" />
2. in java file.
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
super.loadUrl("file:///android_asset/www/index.html");
WebSettings settings = appView.getSettings();
settings.setBuiltInZoomControls(true);
settings.setSupportZoom(true);
settings.setDefaultZoom(ZoomDensity.FAR);
}
Wednesday, 15 August 2012
Unit Testing in Python
I want to do automated unit testing for my class that I had written in Python.
To do automated unit testing I need three items:
1. The class I want to test.
2. The unit testing class.
3. The test runner.
Step 1:
-------
I created my class and named it as controllerTesting.py.
I added functions inside the file as below:
class Test():
def returnZero(self):
return 0
def returnNonZero(self):
return 12
def returnSumNumber(self, number1, number2):
return number1 + number2
Step 2:
-------
I created the file (test.py) and add the functions to test the functions in controllerTesting.py
I added code as below:
import unittest
from controllers.controllerTesting import Test
class TestControllerTest(unittest.TestCase):
def testZeroReturn(self):
val = 0
t = Test()
self.assertEqual(val, t.returnZero())
def testNonZeroReturn(self):
val = 0
t = Test()
self.assertNotEqual(val, t.returnNonZero())
def testSumNumber(self):
total = 4
t = Test()
r = t.returnSumNumber(2, 2)
self.assertEqual(total, r, 'incorrect default size')
Step 3:
-------
I created the test runner (test_runner.py) and add these code to the file.
import unittest
from test import TestControllerTest
if __name__ == '__main__':
suite = unittest.TestLoader().loadTestsFromTestCase(TestControllerTest)
suite = unittest.TestSuite()
suite.addTest(unittest.makeSuite(TestControllerTest))
log_file = 'unit_testing_log.txt'
f = open(log_file, "w")
runner = unittest.TextTestRunner(f, verbosity=2).run(suite)
unittest.TextTestRunner(verbosity=2).run(suite)
Step 4:
-------
I Ran the unit test using the command.
python test_runner.py
The output of the testing were printed in unit_testing_log.txt located in the same directory of the unit testing file.
Output example:
testNonZeroReturn (test.TestControllerTest) ... ok
testSumNumber (test.TestControllerTest) ... FAIL
testZeroReturn (test.TestControllerTest) ... ok
testNonZeroReturn (test1.TestControllerTest2) ... ok
testSumNumber (test1.TestControllerTest2) ... ok
testZeroReturn (test1.TestControllerTest2) ... ok
======================================================================
FAIL: testSumNumber (test.TestControllerTest)
----------------------------------------------------------------------
Traceback (most recent call last):
File "test.py", line 33, in testSumNumber
self.assertEqual(total, r, 'incorrect default size')
AssertionError: 4 != 0 : incorrect default size
----------------------------------------------------------------------
Ran 6 tests in 0.001s
FAILED (failures=1)
To do automated unit testing I need three items:
1. The class I want to test.
2. The unit testing class.
3. The test runner.
Step 1:
-------
I created my class and named it as controllerTesting.py.
I added functions inside the file as below:
class Test():
def returnZero(self):
return 0
def returnNonZero(self):
return 12
def returnSumNumber(self, number1, number2):
return number1 + number2
Step 2:
-------
I created the file (test.py) and add the functions to test the functions in controllerTesting.py
I added code as below:
import unittest
from controllers.controllerTesting import Test
class TestControllerTest(unittest.TestCase):
def testZeroReturn(self):
val = 0
t = Test()
self.assertEqual(val, t.returnZero())
def testNonZeroReturn(self):
val = 0
t = Test()
self.assertNotEqual(val, t.returnNonZero())
def testSumNumber(self):
total = 4
t = Test()
r = t.returnSumNumber(2, 2)
self.assertEqual(total, r, 'incorrect default size')
Step 3:
-------
I created the test runner (test_runner.py) and add these code to the file.
import unittest
from test import TestControllerTest
if __name__ == '__main__':
suite = unittest.TestLoader().loadTestsFromTestCase(TestControllerTest)
suite = unittest.TestSuite()
suite.addTest(unittest.makeSuite(TestControllerTest))
log_file = 'unit_testing_log.txt'
f = open(log_file, "w")
runner = unittest.TextTestRunner(f, verbosity=2).run(suite)
unittest.TextTestRunner(verbosity=2).run(suite)
Step 4:
-------
I Ran the unit test using the command.
python test_runner.py
The output of the testing were printed in unit_testing_log.txt located in the same directory of the unit testing file.
Output example:
testNonZeroReturn (test.TestControllerTest) ... ok
testSumNumber (test.TestControllerTest) ... FAIL
testZeroReturn (test.TestControllerTest) ... ok
testNonZeroReturn (test1.TestControllerTest2) ... ok
testSumNumber (test1.TestControllerTest2) ... ok
testZeroReturn (test1.TestControllerTest2) ... ok
======================================================================
FAIL: testSumNumber (test.TestControllerTest)
----------------------------------------------------------------------
Traceback (most recent call last):
File "test.py", line 33, in testSumNumber
self.assertEqual(total, r, 'incorrect default size')
AssertionError: 4 != 0 : incorrect default size
----------------------------------------------------------------------
Ran 6 tests in 0.001s
FAILED (failures=1)
Thursday, 21 June 2012
How to import module from different folder in Python
Let say we have a folder structure like this:
Project
-- controllers
-- controllerA.py
-- unit_testing
-- test_controllerA.py
We want to import controllerA to be used in test_controllerA. So in test_controllerA.py we should add these code:
/** test_controllerA .py **/
import sys
import os.path
sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), os.path.pardir)))
/**Now we can import the class **/
from controllers.controllerA import controllerA
Project
-- controllers
-- controllerA.py
-- unit_testing
-- test_controllerA.py
We want to import controllerA to be used in test_controllerA. So in test_controllerA.py we should add these code:
/** test_controllerA .py **/
import sys
import os.path
sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), os.path.pardir)))
/**Now we can import the class **/
from controllers.controllerA import controllerA
Thursday, 31 May 2012
PHP TDD
We can use SimpleTest to write program in TDD style.
0. Download SimpleTest.
1. Add the unit testing and report file.
2. Subclass the UnitTestCase
3. Write the function to do the unit testing.
4. Run the test.
Example:
<?php
require_once('simpletest/unit_tester.php');
require_once('simpletest/reporter.php');
require_once "Location.php"; // class to test
class MyTestingClass extends UnitTestCase
{
/*
* Test distance calculation function in Location class.
*/
function TestCalculateDistance()
{
$point1 = array('x'=>0, 'y'=>0);
$point2 = array('x'=>10, 'y'=>10);
$distance = number_format(14.142135623731, 2, '.', '');
$location = new Location();
$retDistance = $location->calculateDistance($point1, $point2); // Function in Location class
$retDistance = number_format($retDistance, 2, '.', '');
$this->assertEqual($distance, $retDistance); // return true if distance is calculated correctly
}
}
$test = new TestLocation();
$test->run(new HtmlReporter()); // run the test
?>
0. Download SimpleTest.
1. Add the unit testing and report file.
2. Subclass the UnitTestCase
3. Write the function to do the unit testing.
4. Run the test.
Example:
<?php
require_once('simpletest/unit_tester.php');
require_once('simpletest/reporter.php');
require_once "Location.php"; // class to test
class MyTestingClass extends UnitTestCase
{
/*
* Test distance calculation function in Location class.
*/
function TestCalculateDistance()
{
$point1 = array('x'=>0, 'y'=>0);
$point2 = array('x'=>10, 'y'=>10);
$distance = number_format(14.142135623731, 2, '.', '');
$location = new Location();
$retDistance = $location->calculateDistance($point1, $point2); // Function in Location class
$retDistance = number_format($retDistance, 2, '.', '');
$this->assertEqual($distance, $retDistance); // return true if distance is calculated correctly
}
}
$test = new TestLocation();
$test->run(new HtmlReporter()); // run the test
?>
Subscribe to:
Posts (Atom)