记录阿里巴巴QA架构组成长点滴。2008年关键词为效率,技术,影响力!QA/测试架构师定义:开发和设计测试框架测试库;纵横全局的考虑产品的功能,设计复杂的测试系统;负责研发某一项特定的测试技术;为公司考虑如何提高测试效率。领导公司测试技术的发展和测试策略上的方向,关注整个公司的测试部门的问题,前瞻性的考虑未来的版本的测试策略和技术。测试架构师计划/设计测试平台,关注着产品的测试过程,提供咨询服务,影响到公司内的测试机构测试社区,以及开发机构等,对产品各个方面施加深远而正确的影响,最终提高整体软件质量。

用字典对象实现堆栈的数据结构

上一篇 / 下一篇  2008-05-12 20:32:57 / 个人分类:自动化测试框架与实现

By Wiston Li

堆栈的数据结构的特征是Last in First out, 并被广泛应用,如错误的保护于处理,后出现的问题先处理,直到所有错误处理完毕。

下面一个程序采用字典对象实现堆栈, 用class 实现:

 

Class clsStack  '定义堆栈

   Private m_stack ' Dictionary Private member

   ' ** Class Constructor

   Private Sub Class_Initialize  

      Set m_stack = CreateObject( "scrīpting.Dictionary" )

      m_stack.Add "next", 0

   End Sub

   ' ** Class Destructor

   Private Sub Class_Terminate  

      If m_stack.Count > 0 Then

         m_stack.RemoveAll

      End If

      Set m_stack = Nothing

   End Sub       ' 初始化变量与函数

 

  

Public Property Get Count() ' 定义count方法

   Count = CLng( m_stack( "next" ) )

End Property

 

Public Property Get IsEmpty() ' 定义isEmpty方法

   IsEmpty = CBool( Me.Count = 0 )

End Property

 

Public Sub Push( ByVal data ) ' 定义push方法

   m_stack.Item( m_stack.Item( "next" ) ) = data

   m_stack.Item( "next" ) = CLng( m_stack.Item( "next" ) ) + 1

End Sub

 

Public Function Pop()' 定义pop方法

   If Me.IsEmpty Then

      Reporter.ReportEvent micFail, "Stack", "The Stack is empty"

      Pop = Empty

   End If

   Pop = m_stack.Item( m_stack.Item( "next" ) - 1 )

   m_stack.Remove m_stack.Item( "next" ) - 1

   m_stack.Item( "next" ) = CLng( m_stack.Item( "next" ) ) - 1

End Function

 

 

Public Function Peek() ' 定义peek方法

   If Me.IsEmpty Then

      Reporter.ReportEvent micFail, "Stack", "The stack is empty"

      Peek = Empty

   End If

   Peek = m_stack.Item( m_stack.Item( "next" ) - 1 )

End Function

 

Public Sub Clean() ' 定义clean方法

   If Not Me.IsEmpty Then

      m_stack.RemoveAll

      m_stack.Add "next", 0

   End If

End Sub

Public Function Clone()' 定义clone方法

   Dim m_cloned, key

   Set m_cloned = CreateObject( "scrīpting.Dictionary" )

   For Each key in m_stack.Keys

      m_cloned.Add key, m_stack( key )

   Next

   Set Clone = m_cloned

End Function

Public Function ToArray()' 定义ToArray方法

   Dim m_cloned

  

   Set m_cloned = Me.Clone()

   m_cloned.Remove( "curr" )

   m_cloned.Remove( "next" )

   ToArray = m_cloned.Items

End Function

End Class

 

' How it works?

Set stack = New clsStack

Print "stack.Count : " & stack.Count     ' Prints zero

Print "stack.IsEmpty : " & stack.IsEmpty ' Prints True

' ** Adding a value

stack.Push "Message 1″

Print "stack.Count : " & stack.Count       ' Prints 2

Print "stack.IsEmpty : " & stack.IsEmpty   ' Prints False

Print "stack.Peek : " & queue.Peek()       ' Prints "Message 2″

Print arr = stack.ToArray()

Do While stack.IsEmpty = False

   Print stack.Pop()

Loop

Set stack = Nothing

 

 


TAG: 自动化测试框架与实现

引用 删除 xyuan007   /   2008-08-01 11:51:54
vbscript就是这方面不好,语言有些落后了,好多东西得自己写。
RUBY就好多了,ARRAY本身就是一个STACK。
可以考虑用WATIR等测试框架啊。
 

评分:0

我来说两句

日历

« 2024-03-25  
     12
3456789
10111213141516
17181920212223
24252627282930
31      

数据统计

  • 访问量: 153168
  • 日志数: 163
  • 文件数: 1
  • 建立时间: 2008-02-26
  • 更新时间: 2008-12-10

RSS订阅

Open Toolbar