Coverage for pybeepop/beepop/bee.py: 72%

29 statements  

« prev     ^ index     » next       coverage.py v7.11.0, created at 2025-10-30 13:34 +0000

1"""BeePop+ Base Bee Module. 

2 

3This module contains the base Bee class that serves as the foundation for all 

4honey bee life stages in the colony simulation. The Bee class provides common 

5attributes and methods shared across eggs, larvae, brood, and adult bees. 

6 

7The Bee class implements the basic properties of bee populations including 

8population counts, age tracking, and vitality status. All specific life stages 

9inherit from this base class and extend it with stage-specific attributes 

10and behaviors. 

11""" 

12 

13 

14class Bee: 

15 """Base class for all honey bee life stages in the colony simulation. 

16 

17 This class provides the fundamental attributes and methods common to all 

18 bee life stages. It tracks population counts, age, and survival status 

19 for cohorts of bees as they progress through their lifecycle. 

20 

21 The Bee class serves as the foundation for the age-structured population 

22 model, where bees are grouped into cohorts that age and transition between 

23 life stages over time. 

24 

25 Attributes: 

26 number (int): Population count for this bee cohort 

27 age (float): Age of this cohort in days since creation 

28 alive (bool): Whether this cohort is still alive and active 

29 """ 

30 

31 def __init__(self, number=0): 

32 """Initialize a new Bee cohort. 

33 

34 Creates a bee population cohort with specified initial size and 

35 default attributes for age and survival status. 

36 

37 Args: 

38 number (int, optional): Initial population size for this cohort. 

39 Must be non-negative integer. Defaults to 0. 

40 """ 

41 # Enforce integer type to match C++ CBee::number (int) 

42 self.number = int(number) 

43 self.age = 0.0 # days 

44 self.alive = True 

45 

46 def set_number(self, num): 

47 # Enforce integer type to match C++ CBee::number (int) 

48 self.number = int(num) 

49 

50 def get_number(self): 

51 return self.number 

52 

53 def kill(self): 

54 self.alive = False 

55 self.number = 0 

56 

57 def is_alive(self): 

58 return self.alive 

59 

60 def reset(self): 

61 self.number = 0 

62 self.age = 0.0 

63 self.alive = True 

64 

65 def __eq__(self, other): 

66 if not isinstance(other, Bee): 

67 return False 

68 return self.alive == other.alive and self.number == other.number 

69 

70 def __copy__(self): 

71 new_bee = Bee(self.number) 

72 new_bee.age = self.age 

73 new_bee.alive = self.alive 

74 return new_bee 

75 

76 def __str__(self): 

77 return f"Bee(number={self.number}, age={self.age}, alive={self.alive})"