Top Banner
FROM THE TESTING TRENCHES COMMON LOGIC LAPSES AND HOW TO AVOID THEM
37

FROM THE TESTING TRENCHES COMMON LOGIC LAPSES AND HOW TO AVOID THEM.

Dec 17, 2015

Download

Documents

Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: FROM THE TESTING TRENCHES COMMON LOGIC LAPSES AND HOW TO AVOID THEM.

FROM THE TESTING TRENCHESCOMMON LOGIC LAPSES AND HOW TO AVOID THEM

Page 2: FROM THE TESTING TRENCHES COMMON LOGIC LAPSES AND HOW TO AVOID THEM.

2Copy r ight © 2014, SAS Ins t i tu te Inc . A l l r ights reserved.

DISCLAIMER

• The views and opinions expressed in the following PowerPoint slides are

those of the individual presenter and should not be attributed to the Research

Triangle SAS Users Group, or any organization with which the presenter is

employed or affiliated.

• These PowerPoint slides are the intellectual property of the individual

presenter and are protected under the copyright laws of the United States of

America and other countries. Used by permission. All rights reserved.

Page 3: FROM THE TESTING TRENCHES COMMON LOGIC LAPSES AND HOW TO AVOID THEM.

3Copy r ight © 2014, SAS Ins t i tu te Inc . A l l r ights reserved.

WHAT IS A LOGIC LAPSE?

• Code runs without error• Output looks reasonable• Log files look reasonable• Off to QA for testing and …

Page 4: FROM THE TESTING TRENCHES COMMON LOGIC LAPSES AND HOW TO AVOID THEM.

4Copy r ight © 2014, SAS Ins t i tu te Inc . A l l r ights reserved.

KA-BOOM!

Page 5: FROM THE TESTING TRENCHES COMMON LOGIC LAPSES AND HOW TO AVOID THEM.

5Copy r ight © 2014, SAS Ins t i tu te Inc . A l l r ights reserved.

LOGIC LAPSES

• Applying a DATETIME format to a SAS date

Page 6: FROM THE TESTING TRENCHES COMMON LOGIC LAPSES AND HOW TO AVOID THEM.

6Copy r ight © 2014, SAS Ins t i tu te Inc . A l l r ights reserved.

WHAT IT LOOKS LIKE…

Page 7: FROM THE TESTING TRENCHES COMMON LOGIC LAPSES AND HOW TO AVOID THEM.

7Copy r ight © 2014, SAS Ins t i tu te Inc . A l l r ights reserved.

HOW TO FIX…

• Apply date format to date variableselect IssueDate format=DATE9. as Issue_Date

• Create DATETIME variable and apply DATETIME formatselect dhms(IssueDate,0,0,0) format=DATETIME23. as Issue_DTTM

Page 8: FROM THE TESTING TRENCHES COMMON LOGIC LAPSES AND HOW TO AVOID THEM.

8Copy r ight © 2014, SAS Ins t i tu te Inc . A l l r ights reserved.

LOGIC LAPSES

• Applying a DATETIME format to a SAS date• Not checking for undefined formats

Page 9: FROM THE TESTING TRENCHES COMMON LOGIC LAPSES AND HOW TO AVOID THEM.

9Copy r ight © 2014, SAS Ins t i tu te Inc . A l l r ights reserved.

WHAT IT LOOKS LIKE…

Page 10: FROM THE TESTING TRENCHES COMMON LOGIC LAPSES AND HOW TO AVOID THEM.

10Copy r ight © 2014, SAS Ins t i tu te Inc . A l l r ights reserved.

HOW TO FIX…

Page 11: FROM THE TESTING TRENCHES COMMON LOGIC LAPSES AND HOW TO AVOID THEM.

11Copy r ight © 2014, SAS Ins t i tu te Inc . A l l r ights reserved.

LOGIC LAPSES

• Applying a DATETIME format to a SAS date• Not checking for undefined formats• Parsing incorrectly

Page 12: FROM THE TESTING TRENCHES COMMON LOGIC LAPSES AND HOW TO AVOID THEM.

12Copy r ight © 2014, SAS Ins t i tu te Inc . A l l r ights reserved.

WHAT IT LOOKS LIKE…

Page 13: FROM THE TESTING TRENCHES COMMON LOGIC LAPSES AND HOW TO AVOID THEM.

13Copy r ight © 2014, SAS Ins t i tu te Inc . A l l r ights reserved.

HOW TO FIX…

Page 14: FROM THE TESTING TRENCHES COMMON LOGIC LAPSES AND HOW TO AVOID THEM.

14Copy r ight © 2014, SAS Ins t i tu te Inc . A l l r ights reserved.

LOGIC LAPSES

• Applying a DATETIME format to a SAS date• Not checking for undefined formats• Parsing incorrectly• Not accounting for case sensitivity

Page 15: FROM THE TESTING TRENCHES COMMON LOGIC LAPSES AND HOW TO AVOID THEM.

15Copy r ight © 2014, SAS Ins t i tu te Inc . A l l r ights reserved.

WHAT IT LOOKS LIKE…

9 proc sql;10 create table Case_Example_1 as11 select City,County,State,ZIP12 from Case_Example13 where city="RALEIGH";NOTE: Table WORK.CASE_EXAMPLE_1 created, with 0 rows and 4 columns.

13 ! quit;

Page 16: FROM THE TESTING TRENCHES COMMON LOGIC LAPSES AND HOW TO AVOID THEM.

16Copy r ight © 2014, SAS Ins t i tu te Inc . A l l r ights reserved.

HOW TO FIX…

15 proc sql;16 create table Case_Example_2 as17 select City,County,State,ZIP18 from Case_Example19 where upcase(city)="RALEIGH";NOTE: Table WORK.CASE_EXAMPLE_2 created, with 44 rows and 4 columns.

19 ! quit;

Page 17: FROM THE TESTING TRENCHES COMMON LOGIC LAPSES AND HOW TO AVOID THEM.

17Copy r ight © 2014, SAS Ins t i tu te Inc . A l l r ights reserved.

LOGIC LAPSES

• Applying a DATETIME format to a SAS date• Not checking for undefined formats• Parsing incorrectly• Not accounting for case sensitivity• Not accounting for leading or trailing blanks

Page 18: FROM THE TESTING TRENCHES COMMON LOGIC LAPSES AND HOW TO AVOID THEM.

18Copy r ight © 2014, SAS Ins t i tu te Inc . A l l r ights reserved.

WHAT IT LOOKS LIKE…

15 proc sql;16 create table Example_1 as17 select distinct a.ncgeneralstatute || ' - ' ||b.ncgeneralstatutedescription as NCGS_CAT18 from extract.sor_offense as a19 left join extract.sor_refncstatute as b20 on a.ncgeneralstatute=b.ncgeneralstatute21 ;

Page 19: FROM THE TESTING TRENCHES COMMON LOGIC LAPSES AND HOW TO AVOID THEM.

19Copy r ight © 2014, SAS Ins t i tu te Inc . A l l r ights reserved.

HOW TO FIX…

23 proc sql;24 create table Example_2 as25 select distinct catx(' - ', a.ncgeneralstatute,b.ncgeneralstatutedescription) as NCGS_CATX26 from extract.sor_offense as a27 left join extract.sor_refncstatute as b28 on a.ncgeneralstatute=b.ncgeneralstatute29 ;

Page 20: FROM THE TESTING TRENCHES COMMON LOGIC LAPSES AND HOW TO AVOID THEM.

20Copy r ight © 2014, SAS Ins t i tu te Inc . A l l r ights reserved.

LOGIC LAPSES

• Applying a DATETIME format to a SAS date• Not checking for undefined formats• Parsing incorrectly• Not accounting for case sensitivity• Not accounting for leading or trailing blanks• Not accounting for hex characters

Page 21: FROM THE TESTING TRENCHES COMMON LOGIC LAPSES AND HOW TO AVOID THEM.

21Copy r ight © 2014, SAS Ins t i tu te Inc . A l l r ights reserved.

WHAT IT LOOKS LIKE…

31 proc sql;32 create table Hex_Example_1 as33 select *34 from Hex_Example35 where upcase(city)="RALEIGH";NOTE: Table WORK.HEX_EXAMPLE_1 created, with 0 rows and 5 columns.

35 ! quit;

Page 22: FROM THE TESTING TRENCHES COMMON LOGIC LAPSES AND HOW TO AVOID THEM.

22Copy r ight © 2014, SAS Ins t i tu te Inc . A l l r ights reserved.

HOW TO FIX…

37 proc sql;38 create table Hex_Example_2 as39 select *40 from Hex_Example41 where upcase(compress(city,,'ak'))="RALEIGH";NOTE: Table WORK.HEX_EXAMPLE_2 created, with 44 rows and 5 columns.

41 ! quit;

Page 23: FROM THE TESTING TRENCHES COMMON LOGIC LAPSES AND HOW TO AVOID THEM.

23Copy r ight © 2014, SAS Ins t i tu te Inc . A l l r ights reserved.

LOGIC LAPSES

• Applying a DATETIME format to a SAS date• Not checking for undefined formats• Parsing incorrectly• Not accounting for case sensitivity• Not accounting for leading or trailing blanks• Not accounting for hex characters• Incorrect handling of endpoints

Page 24: FROM THE TESTING TRENCHES COMMON LOGIC LAPSES AND HOW TO AVOID THEM.

24Copy r ight © 2014, SAS Ins t i tu te Inc . A l l r ights reserved.

WHAT IT LOOKS LIKE…

• Greater than versus Greater than or equal to• Less than versus Less than or equal to• Less than versus Greater than• LE versus GE• Displaying age

Page 25: FROM THE TESTING TRENCHES COMMON LOGIC LAPSES AND HOW TO AVOID THEM.

25Copy r ight © 2014, SAS Ins t i tu te Inc . A l l r ights reserved.

HOW TO FIX…

• Query test data for cases• where date falls inside or outside test range• where date matches endpoints• where birthday matches test date• where date is missing

Page 26: FROM THE TESTING TRENCHES COMMON LOGIC LAPSES AND HOW TO AVOID THEM.

26Copy r ight © 2014, SAS Ins t i tu te Inc . A l l r ights reserved.

LOGIC LAPSES

• Applying a DATETIME format to a SAS date• Not checking for undefined formats• Parsing incorrectly• Not accounting for case sensitivity• Not accounting for leading or trailing blanks• Not accounting for hex characters• Incorrect handling of endpoints• Incorrect sorting (primary/secondary/tertiary)

Page 27: FROM THE TESTING TRENCHES COMMON LOGIC LAPSES AND HOW TO AVOID THEM.

27Copy r ight © 2014, SAS Ins t i tu te Inc . A l l r ights reserved.

WHAT IT LOOKS LIKE…

Page 28: FROM THE TESTING TRENCHES COMMON LOGIC LAPSES AND HOW TO AVOID THEM.

28Copy r ight © 2014, SAS Ins t i tu te Inc . A l l r ights reserved.

LOGIC LAPSES

• Applying a DATETIME format to a SAS date• Not checking for undefined formats• Parsing incorrectly• Not accounting for case sensitivity• Not accounting for leading or trailing blanks• Not accounting for hex characters• Incorrect handling of endpoints• Incorrect sorting (primary/secondary/tertiary)• Losing data when converting text strings to SAS dates

Page 29: FROM THE TESTING TRENCHES COMMON LOGIC LAPSES AND HOW TO AVOID THEM.

29Copy r ight © 2014, SAS Ins t i tu te Inc . A l l r ights reserved.

WHAT IT LOOKS LIKE…

• All digits, but invalid date (leap day in non-leap years)• 19870229

• Missing digits and/or spaces• 194 0116

• Unexpected characters • 20??0704• 0101 &A

• Nonexistent dates• 19821169

Page 30: FROM THE TESTING TRENCHES COMMON LOGIC LAPSES AND HOW TO AVOID THEM.

30Copy r ight © 2014, SAS Ins t i tu te Inc . A l l r ights reserved.

HOW TO FIX…

Page 31: FROM THE TESTING TRENCHES COMMON LOGIC LAPSES AND HOW TO AVOID THEM.

31Copy r ight © 2014, SAS Ins t i tu te Inc . A l l r ights reserved.

LOGIC LAPSES

• Applying a DATETIME format to a SAS date• Not checking for undefined formats• Parsing incorrectly• Not accounting for case sensitivity• Not accounting for leading or trailing blanks• Not accounting for hex characters• Incorrect handling of endpoints• Incorrect sorting (primary/secondary/tertiary)• Losing data when converting text strings to SAS dates• Not imposing integrity constraints on input parameters

Page 32: FROM THE TESTING TRENCHES COMMON LOGIC LAPSES AND HOW TO AVOID THEM.

32Copy r ight © 2014, SAS Ins t i tu te Inc . A l l r ights reserved.

WHAT IT LOOKS LIKE…

Page 33: FROM THE TESTING TRENCHES COMMON LOGIC LAPSES AND HOW TO AVOID THEM.

33Copy r ight © 2014, SAS Ins t i tu te Inc . A l l r ights reserved.

WHAT IT LOOKS LIKE…

year pred succ        2023 A B        

                          

pos account year excess fy_1 fy_2 fy_3succ B 2020 $0.00 $0 $0 $0 succ B 2021 $0.00 $0 $0 $0 succ B 2022 $0.00 $0 $0 $0 succ B 2023 $0.00 $0 $0 $0 pred A 2020 $0.00 $0 $0 $0 pred A 2021 $0.00 $0 $0 $0 pred A 2022 $0.00 $0 $0 $0 pred A 2023 $0.00 $0 $0 $0

Page 34: FROM THE TESTING TRENCHES COMMON LOGIC LAPSES AND HOW TO AVOID THEM.

34Copy r ight © 2014, SAS Ins t i tu te Inc . A l l r ights reserved.

HOW TO FIX…

Page 35: FROM THE TESTING TRENCHES COMMON LOGIC LAPSES AND HOW TO AVOID THEM.

35Copy r ight © 2014, SAS Ins t i tu te Inc . A l l r ights reserved.

LOGIC LAPSE SUMMARY

• Applying a DATETIME format to a SAS date• Not checking for undefined formats• Parsing incorrectly• Not accounting for case sensitivity• Not accounting for leading or trailing blanks• Not accounting for hex characters• Incorrect handling of endpoints• Incorrect sorting (primary/secondary/tertiary)• Losing data when converting text strings to SAS dates• Not imposing integrity constraints on input parameters

Page 36: FROM THE TESTING TRENCHES COMMON LOGIC LAPSES AND HOW TO AVOID THEM.

36Copy r ight © 2014, SAS Ins t i tu te Inc . A l l r ights reserved.

ACKNOWLEDGMENTS

Thanks to the developers whose defects

made this presentation possible.

Page 37: FROM THE TESTING TRENCHES COMMON LOGIC LAPSES AND HOW TO AVOID THEM.

FOR ADDITIONAL INFORMATION, CONTACT:

Jenni M. Elion

Senior Development Tester ▪ SAS Solutions OnDemand

Tel: + 1 919 531 2642 ▪ [email protected]

100 SAS Campus Drive ▪ Cary, NC 27513-2414 USA