fork download
  1. Object subclass: #Polygon
  2. instanceVariableNames: 'apex name originX originY left top right bottom'
  3. classVariableNames: ''
  4. poolDictionaries: ''
  5. category: 'ProgrammingLanguages'!
  6.  
  7. !Polygon methodsFor: 'initialize-release'!
  8.  
  9. initialize: numberApex name: newName oX: x oY: y
  10.  
  11. name:=newName.
  12. apex:=Array new: numberApex.
  13. originX:= x.
  14. originY:= y.
  15. apex at: 1 put: originX@originY ! !@isTest
  16. public class OpportunityValidationTriggerTest {
  17. @isTest static void testCloseDateValidation() {
  18. Opportunity opp = new Opportunity(Name='Test Opportunity', CloseDate=System.today().addDays(-1), StageName='Prospecting', Amount=12000);
  19. insert opp;
  20.  
  21. Test.startTest();
  22. try {
  23. opp.StageName = 'Qualification';
  24. update opp;
  25. } catch(Exception e) {
  26. System.assert(e.getMessage().contains('Opportunity cannot have a Close Date in the past.'));
  27. }
  28. Test.stopTest();
  29. }
  30.  
  31. @isTest static void testStageTransitionLock() {
  32. Opportunity opp = new Opportunity(Name='Test Opportunity', CloseDate=System.today().addDays(7), StageName='Prospecting', Amount=8000);
  33. insert opp;
  34.  
  35. Test.startTest();
  36. try {
  37. opp.StageName = 'Closed Won';
  38. opp.Amount = 15000;
  39. update opp;
  40. } catch(Exception e) {
  41. System.assert(e.getMessage().contains('Opportunity cannot transition directly from Prospecting to Closed Won.'));
  42. }
  43. Test.stopTest();
  44. }
  45.  
  46. @isTest static void testMinimumAmountForClosedWon() {
  47. Opportunity opp = new Opportunity(Name='Test Opportunity', CloseDate=System.today(), StageName='Closed Won', Amount=5000);
  48. insert opp;
  49.  
  50. Test.startTest();
  51. try {
  52. opp.Amount = 8000;
  53. update opp;
  54. } catch(Exception e) {
  55. System.assert(e.getMessage().contains('Opportunity in Closed Won stage must have an Amount greater than or equal to amount 10,000.'));
  56. }
  57. Test.stopTest();
  58. }
  59. }
  60.  
  61. !Polygon methodsFor: 'accessing'!
  62.  
  63. name
  64. ^name!
  65.  
  66. name: new_name
  67. name:=new_name!
  68.  
  69. left
  70. ^left!
  71.  
  72. right
  73. ^right!
  74.  
  75. top
  76. ^top!
  77.  
  78. bottom
  79. ^bottom! !
  80.  
  81.  
  82. Polygon subclass: #Hexagon
  83. instanceVariableNames: 'sideLength'
  84. classVariableNames: ''
  85. poolDictionaries: ''
  86. category: 'ProgrammingLanguages'!
  87.  
  88. !Hexagon methodsFor: 'initialize-release'!
  89.  
  90. initialize: side oX: x oY: y
  91.  
  92. super initialize: 6 name: 'Hexagon' oX: x oY: y.
  93. sideLength:= side.
  94. apex at: 2 put: (x + ((side squared * (3 sqrt))/2))@(y + (0.5 * side)).
  95. apex at: 3 put: (x + ((side squared * (3 sqrt))/2))@(y + (1.5 * side)).
  96. apex at: 4 put: x@(y + (2* side)).
  97. apex at: 5 put: (x - ((side squared * (3 sqrt))/2))@(y + (1.5 * side)).
  98. apex at: 6 put: (x - ((side squared * (3 sqrt))/2))@(y + (0.5 * side)).
  99. left:= (x - ((side squared * (3 sqrt))/2)).
  100. top:= y.
  101. bottom:= (y + (2* side)).
  102. right:= (x + ((side squared * (3 sqrt))/2)).
  103. ! !
  104.  
  105. !Hexagon methodsFor: 'arithmetic'!
  106.  
  107. + figure
  108.  
  109.  
  110. | p newSide |
  111. p:=self area + figure area.
  112. newSide:= (2 * p /((3 * 3 sqrt) sqrt)).
  113.  
  114. ^(Hexagon new) initialize: newSide oX: originX oY: originY!
  115. !
  116.  
  117. !Hexagon methodsFor: 'actions'!
  118.  
  119. getPoints
  120.  
  121. Transcript cr.
  122. Transcript show: ('Dlugosc boku ').
  123. Transcript show: sideLength printString; cr.
  124. Transcript show: ('Pierwszy wierzcholek ').
  125. Transcript show: (apex at: 1) printString; cr.
  126. Transcript show: ('Drugi wierzcholek ').
  127. Transcript show: (apex at: 2) printString; cr.
  128. Transcript show: ('Trzeci wierzcholek ').
  129. Transcript show: (apex at: 3) printString; cr.
  130. Transcript show: ('Czwarty wierzcholek ').
  131. Transcript show: (apex at: 4) printString; cr.
  132. Transcript show: ('Piaty wierzcholek ').
  133. Transcript show: (apex at: 5) printString; cr.
  134. Transcript show: ('Szosty wierzcholek ').
  135. Transcript show: (apex at: 6) printString; cr.
  136. Transcript show: ('Pole pieciokata ').
  137. Transcript show: (self area) printString; cr. !
  138.  
  139. area
  140.  
  141. ^((3 * sideLength squared * 3 sqrt)/2)!
  142.  
  143. move: aa i: bb
  144. self initialize: sideLength oX: (originX + aa) oY: (originY + bb)!
  145. !
  146.  
  147. setOfHexagons := Set new.
  148.  
  149. r1:= (Hexagon new) initialize: 6 oX: 5 oY: 5.
  150. setOfHexagons add: r1.
  151. r2:= (Hexagon new) initialize: 5 oX: 5 oY: 5.
  152. setOfHexagons add: r2.
  153. r3:= (Hexagon new) initialize: 4 oX: 5 oY: 5.
  154. setOfHexagons add: r3.
  155. r4:= (Hexagon new) initialize: 2 oX: 5 oY: 5.
  156. setOfHexagons add: r4.
  157. r5:= (Hexagon new) initialize: 1 oX: 5 oY: 5.
  158. setOfHexagons add: r5.
  159. r6:= (Hexagon new) initialize: 1 oX: 5 oY: 5.
  160. r6 move: 1 i: 1.
  161. setOfHexagons add: r6.
  162. r7:= (Hexagon new).
  163. r7:= r1 + r2.
  164.  
  165.  
  166. setOfHexagons do: [:x|
  167. x getPoints
  168. ].
Success #stdin #stdout #stderr 0.02s 11988KB
stdin
Standard input is empty
stdout
Dlugosc boku 6
Pierwszy wierzcholek 5@5
Drugi wierzcholek Object: 1 error: The program attempted to divide a number by zero
ZeroDivide(Exception)>>signal (ExcHandling.st:254)
SmallInteger(Number)>>zeroDivide (SysExcept.st:1426)
Fraction>>setNumerator:setDenominator: (Fraction.st:485)
Fraction class>>numerator:denominator: (Fraction.st:66)
Fraction>>- (Fraction.st:151)
FloatD(Float)>>printOn:special: (Float.st:533)
FloatD(Float)>>printOn: (Float.st:436)
WriteStream(Stream)>>print: (Stream.st:501)
Point>>printOn: (Point.st:63)
Point(Object)>>printString (Object.st:534)
Hexagon>>getPoints (prog:127)
optimized [] in UndefinedObject>>executeStatements (prog:167)
Set(HashedCollection)>>do: (HashedColl.st:201)
UndefinedObject>>executeStatements (prog:166)
stderr
./prog:15: expected expression