• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Parse a string and create test cases

 
Ranch Hand
Posts: 145
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Dear All,

Here is an assignment that I have taken up.
I am given a string, say for eg: if(a!=c || b!=c, true, false)
This means that if a!=c or b!=c, then validate as true, else validate as false.
Given this scenario I have to create all possible testcases for this string.
Eg:
1. a==c and b==c
2. a!=c
3. b!=cb

Currently I am only doing for the above said scenario; So I have not yet gone generic.
As a first step, I have managed to parse the string and populate a stack with each individual string
The challenge that I am facing is, how to create the test cases based on the stack values.
I am pretty clueless.
Can anyone in this forum help me please.

Thanks!

Regards,
Sriram
 
Saloon Keeper
Posts: 10741
86
Eclipse IDE Firefox Browser MySQL Database VI Editor Java Windows ChatGPT
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Can you post what you've done so far?
 
Sheriff
Posts: 17644
300
Mac Android IntelliJ IDE Eclipse IDE Spring Debian Java Ubuntu Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
What does "each individual string" mean? What does your stack look like after you parse everything?
 
Sriram Sharma
Ranch Hand
Posts: 145
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks for those who took time to reply to my question.

So here is my work till now.
The string that I am using is: if(a!=c || b!=c, true, false)
So, I need to create testcases in three different scenarios
All that I wish to do is something like this

1. a!=c:  true
2. b!=c: true
3. a==c and b==c: false

If not the same output, something which could fit on these lines.



Thanks.

Regards,
Sriram
 
Junilu Lacar
Sheriff
Posts: 17644
300
Mac Android IntelliJ IDE Eclipse IDE Spring Debian Java Ubuntu Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Looks to me like your implementation is too rudimentary and somewhat naive.

You'll need to write a state machine to parse boolean expressions. You need to define a grammar so that you know what state you're in, whether you're in an identifier, have read a separator, in an operator, etc.  A stack will help you keep track of your tokens and expressions and helps determine the order of evaluation.  
reply
    Bookmark Topic Watch Topic
  • New Topic