|
| 1 | +import { describe, expect, it } from 'vitest'; |
| 2 | + |
| 3 | +import { getGridSize, getIsSizeOptimal, getIsSizeTooLarge, getIsSizeTooSmall, getOptimalDimension } from './optimalDimension'; |
| 4 | + |
| 5 | +describe('getOptimalDimension', () => { |
| 6 | + it('returns 512 for sd-1', () => { |
| 7 | + expect(getOptimalDimension('sd-1')).toBe(512); |
| 8 | + }); |
| 9 | + |
| 10 | + it('returns 512 for sd-2', () => { |
| 11 | + expect(getOptimalDimension('sd-2')).toBe(512); |
| 12 | + }); |
| 13 | + |
| 14 | + it('returns 1024 for qwen-image', () => { |
| 15 | + expect(getOptimalDimension('qwen-image')).toBe(1024); |
| 16 | + }); |
| 17 | + |
| 18 | + it('returns 1024 for flux', () => { |
| 19 | + expect(getOptimalDimension('flux')).toBe(1024); |
| 20 | + }); |
| 21 | + |
| 22 | + it('returns 1024 for sdxl', () => { |
| 23 | + expect(getOptimalDimension('sdxl')).toBe(1024); |
| 24 | + }); |
| 25 | + |
| 26 | + it('returns 1024 for z-image', () => { |
| 27 | + expect(getOptimalDimension('z-image')).toBe(1024); |
| 28 | + }); |
| 29 | + |
| 30 | + it('returns 1024 for null/undefined', () => { |
| 31 | + expect(getOptimalDimension(null)).toBe(1024); |
| 32 | + expect(getOptimalDimension(undefined)).toBe(1024); |
| 33 | + }); |
| 34 | +}); |
| 35 | + |
| 36 | +describe('getGridSize', () => { |
| 37 | + it('returns 16 for qwen-image', () => { |
| 38 | + expect(getGridSize('qwen-image')).toBe(16); |
| 39 | + }); |
| 40 | + |
| 41 | + it('returns 16 for flux', () => { |
| 42 | + expect(getGridSize('flux')).toBe(16); |
| 43 | + }); |
| 44 | + |
| 45 | + it('returns 16 for z-image', () => { |
| 46 | + expect(getGridSize('z-image')).toBe(16); |
| 47 | + }); |
| 48 | + |
| 49 | + it('returns 32 for cogview4', () => { |
| 50 | + expect(getGridSize('cogview4')).toBe(32); |
| 51 | + }); |
| 52 | + |
| 53 | + it('returns 8 for sd-1', () => { |
| 54 | + expect(getGridSize('sd-1')).toBe(8); |
| 55 | + }); |
| 56 | + |
| 57 | + it('returns 8 for sdxl', () => { |
| 58 | + expect(getGridSize('sdxl')).toBe(8); |
| 59 | + }); |
| 60 | + |
| 61 | + it('returns 8 for null/undefined', () => { |
| 62 | + expect(getGridSize(null)).toBe(8); |
| 63 | + expect(getGridSize(undefined)).toBe(8); |
| 64 | + }); |
| 65 | +}); |
| 66 | + |
| 67 | +describe('getIsSizeOptimal', () => { |
| 68 | + it('returns true for dimensions near optimal area for qwen-image (1024x1024)', () => { |
| 69 | + expect(getIsSizeOptimal(1024, 1024, 'qwen-image')).toBe(true); |
| 70 | + }); |
| 71 | + |
| 72 | + it('returns true for non-square dimensions within 20% of optimal area', () => { |
| 73 | + // 896x1152 = 1,032,192 vs optimal 1,048,576 (~1.6% diff) |
| 74 | + expect(getIsSizeOptimal(896, 1152, 'qwen-image')).toBe(true); |
| 75 | + }); |
| 76 | + |
| 77 | + it('returns false for dimensions too small (< 80% of optimal area)', () => { |
| 78 | + // 512x512 = 262,144 vs optimal 1,048,576 (~75% too small) |
| 79 | + expect(getIsSizeOptimal(512, 512, 'qwen-image')).toBe(false); |
| 80 | + }); |
| 81 | + |
| 82 | + it('returns false for dimensions too large (> 120% of optimal area)', () => { |
| 83 | + // 2048x2048 = 4,194,304 vs optimal 1,048,576 (~300% too large) |
| 84 | + expect(getIsSizeOptimal(2048, 2048, 'qwen-image')).toBe(false); |
| 85 | + }); |
| 86 | + |
| 87 | + it('returns true for sd-1 at 512x512', () => { |
| 88 | + expect(getIsSizeOptimal(512, 512, 'sd-1')).toBe(true); |
| 89 | + }); |
| 90 | + |
| 91 | + it('returns false for sd-1 at 1024x1024 (too large)', () => { |
| 92 | + expect(getIsSizeOptimal(1024, 1024, 'sd-1')).toBe(false); |
| 93 | + }); |
| 94 | +}); |
| 95 | + |
| 96 | +describe('getIsSizeTooSmall', () => { |
| 97 | + it('returns true when area is below 80% of optimal', () => { |
| 98 | + expect(getIsSizeTooSmall(400, 400, 1024)).toBe(true); |
| 99 | + }); |
| 100 | + |
| 101 | + it('returns false when area is at or above 80% of optimal', () => { |
| 102 | + expect(getIsSizeTooSmall(920, 920, 1024)).toBe(false); |
| 103 | + }); |
| 104 | +}); |
| 105 | + |
| 106 | +describe('getIsSizeTooLarge', () => { |
| 107 | + it('returns true when area exceeds 120% of optimal', () => { |
| 108 | + expect(getIsSizeTooLarge(1200, 1200, 1024)).toBe(true); |
| 109 | + }); |
| 110 | + |
| 111 | + it('returns false when area is at or below 120% of optimal', () => { |
| 112 | + expect(getIsSizeTooLarge(1100, 1024, 1024)).toBe(false); |
| 113 | + }); |
| 114 | +}); |
0 commit comments