Synthia
Generic and flexible data structure generator
Bound.java
Go to the documentation of this file.
1 /*
2  Synthia, a data structure generator
3  Copyright (C) 2019-2021 Laboratoire d'informatique formelle
4  Université du Québec à Chicoutimi, Canada
5 
6  This program is free software: you can redistribute it and/or modify
7  it under the terms of the GNU Lesser General Public License as published
8  by the Free Software Foundation, either version 3 of the License, or
9  (at your option) any later version.
10 
11  This program is distributed in the hope that it will be useful,
12  but WITHOUT ANY WARRANTY; without even the implied warranty of
13  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  GNU Lesser General Public License for more details.
15 
16  You should have received a copy of the GNU Lesser General Public License
17  along with this program. If not, see <http://www.gnu.org/licenses/>.
18  */
19 package ca.uqac.lif.synthia.enumerative;
20 
21 import ca.uqac.lif.synthia.Bounded;
24 import ca.uqac.lif.synthia.Picker;
28 import ca.uqac.lif.synthia.util.Mutator;
29 
30 /**
31  * Return the value picked by a picker a defined number of times.
32  * @ingroup API
33  */
34 public class Bound<T> extends Mutator<T> implements Bounded<T>, Shrinkable<T>
35 {
36  /*@ non_null @*/ protected Picker<Integer> m_length;
37 
38  protected int m_chosenLength;
39 
40  protected int m_currentLength;
41 
42  public Bound(Picker<? extends T> source, Picker<Integer> length)
43  {
44  super(source);
45  m_length = length;
47  m_currentLength = 0;
48  }
49 
50  public Bound(Picker<T> source, int length)
51  {
52  this(source, new Constant<Integer>(length));
53  }
54 
55  @Override
56  public void reset()
57  {
58  m_picker.reset();
59  m_length.reset();
60  m_currentLength = 0;
61  }
62 
63  @Override
64  public T pick()
65  {
67  {
68  throw new NoMoreElementException();
69  }
71  return m_picker.pick();
72  }
73 
74  @Override
75  public Bound<T> duplicate(boolean with_state)
76  {
77  Bound<T> b = new Bound<T>(m_picker.duplicate(with_state), m_length.duplicate(with_state));
78  if (with_state)
79  {
82  }
83  return b;
84  }
85 
86  @Override
87  public boolean isDone()
88  {
90  }
91 
92  @SuppressWarnings("unchecked")
93  @Override
94  public Shrinkable<T> shrink(T o, Picker<Float> decision, float m)
95  {
96  if (!(m_picker instanceof Shrinkable))
97  {
99  }
100  return new Bound<T>(((Shrinkable<T>) m_picker).shrink(o, decision, 1), m_length);
101  }
102 
103  @Override
104  public Shrinkable<T> shrink(T o)
105  {
106  return shrink(o, RandomFloat.instance, 1);
107  }
108 }
ca.uqac.lif.synthia.Picker
Picks an object.
Definition: Picker.java:36
ca.uqac.lif.synthia.enumerative.Bound.m_length
Picker< Integer > m_length
Definition: Bound.java:36
ca.uqac.lif.synthia.enumerative.Bound.Bound
Bound(Picker< T > source, int length)
Definition: Bound.java:50
ca.uqac.lif.synthia.Shrinkable
Interface signaling that a picker can be shrunk.
Definition: Shrinkable.java:36
ca.uqac.lif.synthia.util.Mutator.m_picker
Picker<? extends T > m_picker
The underlying picker producing the values to transform.
Definition: Mutator.java:38
ca.uqac.lif.synthia.util
Miscellaneous pickers performing various functions.
Definition: ArrayPicker.java:19
ca.uqac.lif.synthia.random.RandomFloat.instance
static final transient RandomFloat instance
A public static instance of RandomFloat.
Definition: RandomFloat.java:45
ca.uqac
ca.uqac.lif.synthia.random
Pickers that produce pseudo-random objects such as numbers.
Definition: AffineTransform.java:19
ca.uqac.lif.synthia
Definition: Bounded.java:19
ca.uqac.lif.synthia.util.Constant
Picker that returns the same object every time.
Definition: Constant.java:37
ca.uqac.lif.synthia.enumerative.Bound.pick
T pick()
Picks an object.
Definition: Bound.java:64
ca.uqac.lif.synthia.enumerative.Bound.shrink
Shrinkable< T > shrink(T o, Picker< Float > decision, float m)
Shrinks a picker.
Definition: Bound.java:94
ca.uqac.lif
ca.uqac.lif.synthia.enumerative.Bound.shrink
Shrinkable< T > shrink(T o)
Shrinks a picker with default parameters.
Definition: Bound.java:104
ca.uqac.lif.synthia.Bounded
Interface used to signal that a picker enumerates all values from a set.
Definition: Bounded.java:26
ca.uqac.lif.synthia.enumerative.Bound.m_chosenLength
int m_chosenLength
Definition: Bound.java:38
ca
ca.uqac.lif.synthia.enumerative.Bound.Bound
Bound(Picker<? extends T > source, Picker< Integer > length)
Definition: Bound.java:42
ca.uqac.lif.synthia.Picker.pick
T pick()
Picks an object.
ca.uqac.lif.synthia.enumerative.Bound
Return the value picked by a picker a defined number of times.
Definition: Bound.java:34
ca.uqac.lif.synthia.enumerative.Bound.duplicate
Bound< T > duplicate(boolean with_state)
Creates a copy of the picker.
Definition: Bound.java:75
ca.uqac.lif.synthia.enumerative.Bound.m_currentLength
int m_currentLength
Definition: Bound.java:40
ca.uqac.lif.synthia.util.Mutator
A picker that applies a transformation ("mutation") on the value produced by another picker.
Definition: Mutator.java:33
ca.uqac.lif.synthia.random.RandomFloat
Picks a floating point number uniformly in an interval.
Definition: RandomFloat.java:30
ca.uqac.lif.synthia.NoMoreElementException
An exception to throw when a picker can't pick an other element.
Definition: NoMoreElementException.java:25
ca.uqac.lif.synthia.enumerative.Bound.reset
void reset()
Puts the picker back into its initial state.
Definition: Bound.java:56
ca.uqac.lif.synthia.Picker.duplicate
Picker< T > duplicate(boolean with_state)
Creates a copy of the picker.
ca.uqac.lif.synthia.enumerative.Bound.isDone
boolean isDone()
Signals if the picker enumerates all values from a set.
Definition: Bound.java:87
ca.uqac.lif.synthia.Picker.reset
void reset()
Puts the picker back into its initial state.
ca.uqac.lif.synthia.CannotShrinkException
An exception to throw when a picker can't pick an other element.
Definition: CannotShrinkException.java:25