testfns.py :  » Language-Interface » VB-to-Python-Converter » vb2py-0.2 » test » Python Open Source

Home
Python Open Source
1.3.1.2 Python
2.Ajax
3.Aspect Oriented
4.Blog
5.Build
6.Business Application
7.Chart Report
8.Content Management Systems
9.Cryptographic
10.Database
11.Development
12.Editor
13.Email
14.ERP
15.Game 2D 3D
16.GIS
17.GUI
18.IDE
19.Installer
20.IRC
21.Issue Tracker
22.Language Interface
23.Log
24.Math
25.Media Sound Audio
26.Mobile
27.Network
28.Parser
29.PDF
30.Project Management
31.RSS
32.Search
33.Security
34.Template Engines
35.Test
36.UML
37.USB Serial
38.Web Frameworks
39.Web Server
40.Web Services
41.Web Unit
42.Wiki
43.Windows
44.XML
Python Open Source » Language Interface » VB to Python Converter 
VB to Python Converter » vb2py 0.2 » test » testfns.py
# Created by Leo from: C:\Development\Python22\Lib\site-packages\vb2py\vb2py.leo

from unittest import *
from testframework import *

# << Fn tests >> (1 of 4)
# Simple function
tests.append(("""
Function _square(x)
  _square = x*x
End Function
a = _square(10)
""", {"a" : 100}))

# Simple function with a type
tests.append(("""
Function _square(x) As Single
  _square = x*x
End Function
a = _square(10)
""", {"a" : 100}))

# Accidental non-return
tests.append(("""
Function _square(x)
End Function
a = _square(10)
""", {"a" : None}))

# Function calling a function
tests.append(("""
Function _double(x)
  _double = 2*x
End Function

Function _squaredouble(x)
  _squaredouble = _double(x) * _double(x)
End Function

a = _squaredouble(10)
""", {"a" : 400}))

# Function with exit
tests.append(("""
Function _square(x)
  If x > 0 Then
    _square = x*x
    Exit Function
  End If
  _square = -(x*x)
End Function
a = _square(10)
b = _square(-10)
""", {"a" : 100, "b" : -100}))

# Simple function with no arguments, must detect that it is a function call
tests.append(("""
Function _square()
  _square = 100
End Function
a = _square
""", {"a" : 100}))
# << Fn tests >> (2 of 4)
# Recursive function
tests.append(("""
Function _factorial(x)
  If x = 0 Then
    _factorial = 1
  Else
    _factorial = _factorial(x-1) * x
  End If
End Function
a = _factorial(10)
""", {"a" : 3628800}))
# << Fn tests >> (3 of 4)
# Lots of arguments
tests.append(("""
Function _sum(a,b,c,d,e,f,g,h,i)
  _sum = a+b+c+d+e+f+g+h+i
End Function
a = _sum(1,2,3,4,5,6,7,8,9)
""", {"a" : 45}))

# Lots of arguments with types
tests.append(("""
Function _sum(a As Integer,b As Single,c,d As String,e,f,g As Single,h,i)
  _sum = a+b+c+d+e+f+g+h+i
End Function
a = _sum(1,2,3,4,5,6,7,8,9)
""", {"a" : 45}))

# Some arguments with options
tests.append(("""
Function _sum(a, b, Optional c)
  If IsMissing(c) Then c = 10
  _sum = a+b+c
End Function
a = _sum(1,2,3)
b = _sum(1,2)
""", {"a" : 6, "b" : 13}))

# Some arguments with options and defaults
tests.append(("""
Function _sum(a, b, Optional c=10)
  _sum = a+b+c
End Function
a = _sum(1,2,3)
b = _sum(1,2)
""", {"a" : 6, "b" : 13}))
# << Fn tests >> (4 of 4)
# Function with named arguments
tests.append(("""
Function _sum(Optional x=1, Optional y=2, Optional z=3)
  _sum = x + y + z
End Function
a = _sum(10, 20, 30)
b = _sum(x:=10)
c = _sum(z:=10)
d = _sum()
f = _sum(x:=10, y:=20, z:=30)
""", {"a" : 60, "b" : 15, "c" : 13, "d" : 6, "f" : 60}))
# -- end -- << Fn tests >>

import vb2py.vbparser
vb2py.vbparser.log.setLevel(0) # Don't print all logging stuff
TestClass = addTestsTo(BasicTest, tests)

if __name__ == "__main__":
  main()
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.