SPONSORS:






User Tag List

Results 1 to 7 of 7
  1. #1
    Junior Member
    Join Date
    May 2002
    Location
    San Jose, CA
    Posts
    13
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Working with lists

    Let me preface this by saying that I am new to SilkTest and that I don't find the documentation to be very useful.

    Now, here is what I am trying to do:

    I have a textwindow in my application that I am copying to the clipboard. I want to compare the contents of the clipboard to the contents of a file. I know that the contents are going to be different up to a certain point. I only want to compare the two after that point. With the code I have now (pasted below), I get an error because I try to increase the index of the list past its upper boundary. My questions are as follows:

    a) Is there a better way to do this?
    b) Is there a way to assign specific elements of a list to a new list? For instance, if I only want the last 6 elements of a list, is there an easy way to assign those elements to a new list?

    [ ] lsCurrent = (Clipboard.GetText())
    [ ] ListRead(lsBase, sPath)
    [ ] iBasePos = ListFind(lsBase, "main:")
    [ ] iBaseCount = ListCount(lsBase)
    [ ] iCurrPos = ListFind(lsCurrent, "main:")
    [-] while (iBasePos < iBaseCount)
    [-] if (lsCurrent[iCurrPos] == lsBase
    [iBasePos])
    [ ] iBasePos = iBasePos + 1
    [ ] iCurrPos = iCurrPos + 1
    [-] else
    [ ] print ("Fail!")
    [ ] print (lsCurrent[iCurrPos], " !
    = ", lsBase[iBasePos])
    [ ] break


    ------------------
    Robin L. Siebler
    Software Test Engineer
    Palm
    -------------------------
    Garunteed to be bug free
    Robin L. Siebler
    Software Test Engineer
    Palm
    -------------------------
    Garunteed to be bug free

  2. #2
    Senior Member
    Join Date
    Jan 2001
    Posts
    750
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Re: Working with lists

    I am not sure if you want to compare the difference or the similarity?

    For my own sanity here my attempts:
    Your problem is that your code is not handling the different size of the lists.

    if you want orderless compare it's a bit messier. I used 1 function for compare and 1 to write the result nicely. So I return a result list from the compare function. Which makes things nicely for me. If you decide to compare and write in the same function then there is no need of the extra list.



    ------------------

  3. #3
    Senior Member
    Join Date
    Nov 1999
    Location
    Eagle, ID,USA
    Posts
    1,035
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Re: Working with lists

    here's a ListCompare function someone years back wrote for our libraries.


    [-] LIST OF ANYTYPE ListCompare (LIST OF ANYTYPE List1, LIST OF ANYTYPE List2)
    [ ] //@PARM [IN] First list
    [ ] //@PARM [IN] Second list
    [ ] LIST OF ANYTYPE Differences
    [ ] ANYTYPE aType
    [ ]
    [ ] DPrint ("ListCompare({List1}, {List2}) called", 8)
    [ ]
    [ ] //Make sure all elements in the first
    [ ] //list are in the second list
    [-] for each aType in List1
    [ ] //If not found
    [-] if (ListFind (List2, aType) == 0)
    [ ] //Add it to the differences list
    [ ] ListAppend (Differences, aType)
    [ ]
    [ ] //Now do the other list
    [-] for each aType in List2
    [ ] //If not found
    [-] if (ListFind (List1, aType) == 0)
    [ ] //Add it to the differences list
    [ ] ListAppend (Differences, aType)
    [ ]
    [ ] return (Differences)
    [ ]

    So you can do 'List of AnyType laList = ListCompare(lsList1,lsList2)'

    This will give you the differences.
    if you want to get just the last 6 items for, say, the file contents, do:

    LIST OF STRING lsList1,lsList2
    ListRead(lsList1,"c:\file.txt")

    INT i
    for i = ListCount (lsList) - 5 to ListCount (lsList)
    ListAppend (lsList2, lsList[i])


    ------------------


    [This message has been edited by TonyM (edited 06-04-2002).]

    [This message has been edited by TonyM (edited 06-04-2002).]
    Have you ever noticed? Anybody going slower than you is an idiot, and anyone going faster than you is a maniac.

  4. #4
    Junior Member
    Join Date
    Jan 2002
    Location
    Santa Clara, Ca. USA
    Posts
    22
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Re: Working with lists

    It may be helpful to have the error that is occurring, is it the copied list that is incrementing past listcount? If the base list shows "main:" in the first postion, you can synch up your lists with a while loop and ListDelete - deleting the list items until you reach main: - then you can do a new listcount. Your if stmt can increment with count += 1 instead of count = count + 1. If you synch up the lists then you can control the index better with listcount, or you can include both lists in the while loop you have, (count < basecount) && (count < listcount). -Len

    ------------------

  5. #5
    Senior Member
    Join Date
    Jul 1999
    Location
    Burlingame CA 94010
    Posts
    502
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Re: Working with lists

    SilkTest has a built-in list comparison feature. It will show you color-coded in the results, exactly what was different, missing and extra between two lists.

    use Verify (lsActual, lsExpected)

    or

    VerifySafely (lsActual, lsExpected)
    if you want a non-fatal error

    VerifySafely can be easily defined by wrapping Verify in a do..except with ExceptLog () called in the except.

    Hope this helps



    ------------------
    John W Green
    jwgreen@automationexpertise.com
    http://www.automationexpertise.com

  6. #6
    Senior Member
    Join Date
    Apr 2001
    Location
    San Diego,CA,USA
    Posts
    108
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Re: Working with lists

    Silks Verify(lslist1,lsList2) will fail if the list were:

    lsList1={...}
    "1"
    "2"
    "3"
    "4"
    "5"

    lsList2={...}
    "5"
    "4"
    "3"
    "2"
    "1"

    hence I suggest you do your own verification if you don't care about the order in the list. and only the contents.

    ------------------

  7. #7
    Senior Member
    Join Date
    Jul 1999
    Location
    Burlingame CA 94010
    Posts
    502
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Re: Working with lists

    You could do ListSort (lsList) before the verifications to make sure both lists were in the same order.

    Interesting side note: ListSort is the only function which uses inout. In other words you pass the list in and its modified and sent back, no return value needed.

    ListSort (lsList)

    Hope this helps


    ------------------
    John W Green
    jwgreen@automationexpertise.com
    http://www.automationexpertise.com

 

 

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  

vBulletin Optimisation provided by vB Optimise v2.6.0 Beta 4 (Pro) - vBulletin Mods & Addons Copyright © 2016 DragonByte Technologies Ltd.
User Alert System provided by Advanced User Tagging v3.0.9 (Pro) - vBulletin Mods & Addons Copyright © 2016 DragonByte Technologies Ltd.
Questions / Answers Form provided by vBAnswers (Pro) - vBulletin Mods & Addons Copyright © 2016 DragonByte Technologies Ltd.
vBNominatevBulletin Mods & Addons Copyright © 2016 DragonByte Technologies Ltd.
Feedback Buttons provided by Advanced Post Thanks / Like (Pro) - vBulletin Mods & Addons Copyright © 2016 DragonByte Technologies Ltd.
Username Changing provided by Username Change (Free) - vBulletin Mods & Addons Copyright © 2016 DragonByte Technologies Ltd.
BetaSoft Inc.
Digital Point modules: Sphinx-based search
All times are GMT -8. The time now is 05:56 PM.

Copyright BetaSoft Inc.