Advertisement
Guest User

Untitled

a guest
May 24th, 2019
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.99 KB | None | 0 0
  1. @isTest
  2. public static TestMethod void DataTypes(){
  3.  
  4. string text1 = 'this text';
  5. string text2 = 'that text';
  6.  
  7. string text3 = text1 + text2;
  8. System.debug(text3);
  9. text3 = text3 + 'more text';
  10. System.debug(text3);
  11.  
  12. string text4 = text3.toUpperCase();
  13. System.debug('SHOUT! ' + text4);
  14.  
  15. string text5;//FIX ME!!! Turn text4 into a lower case string.
  16. System.debug('whisper' + text5);
  17.  
  18. string text6;//FIX ME!!! Find a string method to remove whitespaces.
  19. System.debug('No more whitespaces: ' + text6);
  20.  
  21. string text7 = text6.remove('text');
  22. System.debug('This is what\'s left: ');//FIX ME!!! Edit the debug output to include text7.
  23.  
  24. string text8 = text7.replace('more', 'less');
  25. System.debug('now with less! ' + text8);
  26.  
  27. string text9 = text8.repeat(2);
  28. System.debug('repeated twice: ' + text9);
  29.  
  30. Integer number1 = text9.length();
  31. System.debug('how long? ' + number1);
  32.  
  33. Integer number2 = text9.indexOf('this');
  34. System.debug('find this: ' + number2);
  35.  
  36. Integer number3;//FIX ME!!! Use indexOf() to find 'that' in text9.
  37. System.debug('find that: ' + number3);
  38.  
  39. Integer number4 = text9.LastIndexOf('that');
  40. System.assertEquals(16, number4, 'Expected value should equal actual value returned by lastIndexOf()');
  41.  
  42. Integer number5 = text9.IndexOf('less');
  43. System.assertEquals(null,null);//FIX ME!! Replace nulls with the expected index and the actual number5 result
  44.  
  45. //define some numbers we'll use to work with Integers and operators
  46. Integer number6 = 6;
  47. Integer number7 = 7;
  48.  
  49. Integer sum1 = number6 + number7;
  50. System.Debug('do the math: ' + sum1);
  51. System.Debug('x++ returns value then increments: ' + sum1++);
  52. System.Debug('what is the value now?: ' + sum1);
  53. System.Debug('++x increments then returns value: ' + ++sum1);
  54. System.assertEquals(15, sum1);
  55.  
  56.  
  57. Integer sum2;//FIX ME!!! add number7 to number6
  58. Integer sum3;//FIX ME!!! set sum3 to increment sum2.
  59. //System.assertEquals(, sum3);//FIX ME!!! Uncomment and add your expected result.
  60.  
  61. //What happens if we assign a non-integer value?
  62. Integer decimal0 = number6 / number7;
  63. System.debug('Integer of 2 integers divided: ' + decimal0);
  64.  
  65. //Even though the result is a decimal, 2 Integers divided are still treated as integers.
  66. Decimal decimal1 = number6 / number7;
  67. System.debug('Decimal of 2 integers divided: ' + decimal1);
  68.  
  69. //"Casting" is a useful technique to convert one data type to another.
  70. Decimal decimal2 = (decimal)number6 / (decimal)number7;
  71. System.debug('2 integers "cast" to decimals: ' + decimal2);
  72.  
  73. //Care must be taken when working with different numeric types:
  74. //Explicitly declare Double or Decimal values by adding .0 if no fractional value is present
  75. Double nope = 5/3;
  76. System.debug('Double of divided integers: 5/3 != ' + nope);
  77. Double better = 5.0/3.0;
  78. System.debug('Double of divided integers with .0 added: 5.0/3.0 == ' + better);
  79. //Explicitly declare Long values by adding L if the number is likely to exceed 2147483647
  80. Long wrong = 2147483647 + 1;
  81. System.debug('Maximum integer value of 2147483647 plus 1: ' + wrong);
  82. Long right = 2147483647L + 1;
  83. System.debug('Maximum integer value as a Long plus 1: ' + right);
  84.  
  85. //Dates and times are both tricky and easy to work with.
  86. Date date1 = Date.today();
  87. Datetime datetime1 = Datetime.now();
  88. Time time1 = Time.newInstance(18, 30, 2, 20);
  89. Time time2 = Datetime.now().time();
  90. Date date2 = date1 + 1;
  91. System.debug('Tomorrow: ' + date2);
  92. System.debug('Yesterday: ');//FIX ME!!!
  93. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement