|
| 1 | +import { expect } from 'vitest' |
| 2 | + |
| 3 | +import { sandboxTest } from '../setup' |
| 4 | + |
| 5 | +sandboxTest('log', async ({ sandbox }) => { |
| 6 | + const code = ` |
| 7 | +import numpy as np |
| 8 | +import matplotlib.pyplot as plt |
| 9 | +
|
| 10 | +# Generate x values |
| 11 | +x = np.linspace(0, 100, 100) |
| 12 | +# Calculate y values |
| 13 | +y = np.exp(x) |
| 14 | +
|
| 15 | +# Create the plot |
| 16 | +plt.figure(figsize=(10, 6)) |
| 17 | +plt.plot(x, y, label='y = e^x') |
| 18 | +
|
| 19 | +# Set log scale for the y-axis |
| 20 | +plt.yscale('log') |
| 21 | +
|
| 22 | +# Add labels and title |
| 23 | +plt.xlabel('X-axis') |
| 24 | +plt.ylabel('Y-axis (log scale)') |
| 25 | +plt.title('Graph with Log Scale on Y-axis') |
| 26 | +
|
| 27 | +plt.legend() |
| 28 | +plt.grid(True) |
| 29 | +plt.show() |
| 30 | +` |
| 31 | + |
| 32 | + const result = await sandbox.notebook.execCell(code) |
| 33 | + const graph = result.results[0].graph |
| 34 | + expect(graph).toBeDefined() |
| 35 | + expect(graph.type).toBe('line') |
| 36 | + |
| 37 | + expect(graph.title).toBe('Graph with Log Scale on Y-axis') |
| 38 | + |
| 39 | + expect(graph.x_label).toBe('X-axis') |
| 40 | + expect(graph.y_label).toBe('Y-axis (log scale)') |
| 41 | + |
| 42 | + expect(graph.x_unit).toBeNull() |
| 43 | + expect(graph.y_unit).toBe('log scale') |
| 44 | + |
| 45 | + expect(graph.x_scale).toBe('linear') |
| 46 | + expect(graph.y_scale).toBe('log') |
| 47 | + |
| 48 | + expect(graph.x_ticks.every((x) => typeof x === 'number')).toBe(true) |
| 49 | + expect(graph.y_ticks.every((y) => typeof y === 'number')).toBe(true) |
| 50 | + |
| 51 | + expect(graph.x_tick_labels.every((x) => typeof x === 'string')).toBe(true) |
| 52 | + expect(graph.y_tick_labels.every((y) => typeof y === 'string')).toBe(true) |
| 53 | + |
| 54 | + const lines = graph.elements |
| 55 | + expect(lines.length).toBe(1) |
| 56 | + |
| 57 | + const line = lines[0] |
| 58 | + expect(line.label).toBe('y = e^x') |
| 59 | + expect(line.points.length).toBe(100) |
| 60 | + |
| 61 | + expect( |
| 62 | + line.points.every( |
| 63 | + ([x, y]) => typeof x === 'number' && typeof y === 'number' |
| 64 | + ) |
| 65 | + ).toBe(true) |
| 66 | +}) |
0 commit comments