import { Hashpower } from './hashpower.vo'; describe('Hashpower', () => { describe('create', () => { it('should create Hashpower with value', () => { const hp = Hashpower.create(100); expect(hp.value).toBe(100); }); }); describe('zero', () => { it('should create zero Hashpower', () => { const hp = Hashpower.zero(); expect(hp.value).toBe(0); expect(hp.isZero()).toBe(true); }); }); describe('fromTreeCount', () => { it('should calculate hashpower from tree count and percent', () => { // 10 trees at 2% = 20 hashpower const hp = Hashpower.fromTreeCount(10, 2); expect(hp.value).toBe(20); }); it('should return zero for zero percent', () => { const hp = Hashpower.fromTreeCount(10, 0); expect(hp.value).toBe(0); }); }); describe('validation', () => { it('should throw error for negative value', () => { expect(() => Hashpower.create(-10)).toThrow('算力不能为负数'); }); }); describe('add', () => { it('should add two Hashpower values', () => { const a = Hashpower.create(100); const b = Hashpower.create(50); const result = a.add(b); expect(result.value).toBe(150); }); }); describe('subtract', () => { it('should subtract Hashpower values', () => { const a = Hashpower.create(100); const b = Hashpower.create(30); const result = a.subtract(b); expect(result.value).toBe(70); }); it('should return zero when subtracting larger value', () => { const a = Hashpower.create(50); const b = Hashpower.create(100); const result = a.subtract(b); expect(result.value).toBe(0); }); }); describe('equals', () => { it('should return true for equal values', () => { const a = Hashpower.create(100); const b = Hashpower.create(100); expect(a.equals(b)).toBe(true); }); it('should return false for different values', () => { const a = Hashpower.create(100); const b = Hashpower.create(50); expect(a.equals(b)).toBe(false); }); }); });