Coverage for tests/model_strategies.py: 0%

1"""Define strategies to construct model objects."""

2

3 import typing

4

5 from hypothesis import strategies as st

6

7 from swiift.model.model import DiscreteSpectrum, Floe, Ice, Ocean

8 from tests.physical_strategies import (

9 PHYSICAL_STRATEGIES,

10 PHYSICAL_STRATEGIES_COMPOSITE,

11)

12

13

14@st.composite

15 def spec_mono(draw: st.DrawFn) -> DiscreteSpectrum:

16 return DiscreteSpectrum(

17 draw(st.just(0.5)), draw(PHYSICAL_STRATEGIES[("wave", "frequency")])

18 )

19

20

21@st.composite

22 def spec_poly(draw: st.DrawFn) -> DiscreteSpectrum:

23 n = draw(st.integers(min_value=2, max_value=10))

24 amplitudes = draw(

25 st.lists(

26 PHYSICAL_STRATEGIES[("wave", "amplitude")],

27 min_size=n,

28 max_size=n,

29 unique=True,

30 )

31 )

32 frequencies = draw(

33 st.lists(

34 PHYSICAL_STRATEGIES[("wave", "frequency")],

35 min_size=n,

36 max_size=n,

37 unique=True,

38 )

39 )

40 return DiscreteSpectrum(amplitudes, frequencies)

41

42

43 ocean_and_mono_spectrum = {

44 "ocean": st.builds(

45 Ocean,

46 depth=PHYSICAL_STRATEGIES[("ocean", "depth")],

47 density=PHYSICAL_STRATEGIES[("ocean", "density")],

48 ),

49 "spectrum": spec_mono(),

50 "gravity": PHYSICAL_STRATEGIES[("gravity",)],

51}

52

53 ocean_and_poly_spectrum = {

54 "ocean": st.builds(

55 Ocean,

56 depth=PHYSICAL_STRATEGIES[("ocean", "depth")],

57 density=PHYSICAL_STRATEGIES[("ocean", "density")],

58 ),

59 "spectrum": spec_poly(),

60 "gravity": PHYSICAL_STRATEGIES[("gravity",)],

61}

62

63 ocean_and_spectrum = {

64 "ocean": st.builds(

65 Ocean,

66 depth=PHYSICAL_STRATEGIES[("ocean", "depth")],

67 density=PHYSICAL_STRATEGIES[("ocean", "density")],

68 ),

69 "spectrum": spec_mono() | spec_poly(),

70 "gravity": PHYSICAL_STRATEGIES[("gravity",)],

71}

72

73 coupled_ocean_ice = {

74 "ocean": st.builds(

75 Ocean,

76 depth=st.shared(PHYSICAL_STRATEGIES[("ocean", "depth")], key="H"),

77 density=st.shared(PHYSICAL_STRATEGIES[("ocean", "density")], key="rhow"),

78 ),

79 "ice": st.shared(

80 st.builds(

81 Ice,

82 density=st.shared(

83 PHYSICAL_STRATEGIES_COMPOSITE["ice_density"](

84 st.shared(PHYSICAL_STRATEGIES[("ocean", "density")], key="rhow")

85 ),

86 key="rhoi",

87 ),

88 frac_toughness=PHYSICAL_STRATEGIES[("ice", "frac_toughness")],

89 poissons_ratio=PHYSICAL_STRATEGIES[("ice", "poissons_ratio")],

90 thickness=PHYSICAL_STRATEGIES_COMPOSITE["ice_thickness"](

91 ocean_density=st.shared(

92 PHYSICAL_STRATEGIES[("ocean", "density")], key="rhow"

93 ),

94 ocean_depth=st.shared(PHYSICAL_STRATEGIES[("ocean", "depth")], key="H"),

95 ice_density=st.shared(

96 PHYSICAL_STRATEGIES_COMPOSITE["ice_density"](

97 st.shared(PHYSICAL_STRATEGIES[("ocean", "density")], key="rhow")

98 ),

99 key="rhoi",

100 ),

101 ),

102 youngs_modulus=PHYSICAL_STRATEGIES[("ice", "youngs_modulus")],

103 ),

104 key="ice",

105 ),

106 "gravity": PHYSICAL_STRATEGIES[("gravity",)],

107}

108

109 coupled_floe = {

110 "floe": st.builds(

111 Floe,

112 left_edge=PHYSICAL_STRATEGIES[("floe", "left_edge")],

113 length=PHYSICAL_STRATEGIES_COMPOSITE["floe_length"](

114 st.shared(coupled_ocean_ice["ice"], key="ice")

115 ),

116 ice=st.shared(coupled_ocean_ice["ice"], key="ice"),

117 )

118} | coupled_ocean_ice

119

120

121 class TestingConstants(typing.TypedDict):

122 ocean: Ocean

123 ice: Ice

124 spec_mono: DiscreteSpectrum

125 spec_poly: DiscreteSpectrum

126 gravity: float

127 length: float

128 left_edge: float

129

130

131 simple_objects: TestingConstants = {

132 "ocean": Ocean(),

133 "ice": Ice(),

134 "spec_mono": DiscreteSpectrum(0.5, 1 / 7),

135 "spec_poly": DiscreteSpectrum((0.1, 0.2), (1 / 7, 1 / 5)),

136 "gravity": 9.8,

137 "length": 101.5,

138 "left_edge": 13.8,

139}